C# 使用流
- 作者: 请叫我-宝哥哥
- 来源: 51数据库
- 2022-12-15
问题描述
流对我来说有点神秘.我不知道何时使用哪个流以及如何使用它们.有人可以向我解释如何使用流吗?
Streams are kind of mysterious to me. I don't know when to use which stream and how to use them. Can someone explain to me how streams are used?
如果我理解正确的话,有三种流类型:
If I understand correctly, there are three stream types:
- 流
- 读取流
- 写流
这是正确的吗?例如,Memorystream 和 FileStream 之间有什么区别?
Is this correct? And, for example, what is the difference between a Memorystream and a FileStream?
推荐答案
stream 是用于传输数据的对象.有一个通用流类 System.IO.Stream,.NET 中的所有其他流类都从该类派生.Stream 类处理字节.
A stream is an object used to transfer data. There is a generic stream class System.IO.Stream, from which all other stream classes in .NET are derived. The Stream class deals with bytes.
具体的流类用于处理字节以外的其他类型的数据.例如:
The concrete stream classes are used to deal with other types of data than bytes. For example:
- 当外部源是文件时使用FileStream 类
- MemoryStream 用于在内存中存储数据
- System.Net.Sockets.NetworkStream 处理网络数据
- The FileStream class is used when the outside source is a file
- MemoryStream is used to store data in memory
- System.Net.Sockets.NetworkStream handles network data
读取器/写入器流,例如 StreamReader 和 StreamWriter 不是流 - 它们不是从 System.IO.Stream 派生的,它们是旨在帮助写入和读取数据以及流式传输!
Reader/writer streams such as StreamReader and StreamWriter are not streams - they are not derived from System.IO.Stream, they are designed to help to write and read data from and to stream!
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源
