C# 使用流

C# using streams(C# 使用流)
本文介绍了C# 使用流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

流对我来说有点神秘.我不知道何时使用哪个流以及如何使用它们.有人可以向我解释如何使用流吗?

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:

  • 读取流
  • 写流

这是正确的吗?例如,MemorystreamFileStream 之间有什么区别?

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

读取器/写入器流,例如 StreamReaderStreamWriter 不是流 - 它们不是从 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# 使用流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to know if a field is numeric in Linq To SQL(如何在 Linq To SQL 中知道字段是否为数字)
Linq2SQl eager load with multiple DataLoadOptions(具有多个 DataLoadOptions 的 Linq2SQl 急切加载)
Extract sql query from LINQ expressions(从 LINQ 表达式中提取 sql 查询)
LINQ Where in collection clause(LINQ Where in collection 子句)
Orderby() not ordering numbers correctly c#(Orderby() 没有正确排序数字 c#)
Why do I get quot;error: ... must be a reference typequot; in my C# generic method?(为什么我会收到“错误:...必须是引用类型?在我的 C# 泛型方法中?)