The community is working on translating this tutorial into Thai, but it seems that no one has started the translation process for this article yet. If you can help us, then please click "More info".
If you are fluent in Thai, then please help us - just point to any untranslated element (highlighted with a yellow left border - remember that images should have their titles translated as well!) inside the article and click the translation button to get started. Or have a look at the current translation status for the Thai language.
If you see a translation that you think looks wrong, then please consult the original article to make sure and then use the vote button to let us know about it.
Please help us by translating the following metadata for the article/chapter, if they are not already translated.
If you are not satisfied with the translation of a specific metadata item, you may vote it down - when it reaches a certain negative threshold, it will be removed. Please only submit an altered translation of a metadata item if you have good reasons to do so!
In the .NET framework, the concept of Streams are used whenever you want to read and/or write data from and to a wide range of sources/destinations, e.g. in-memory, a file, over a network connection or basically any other situation where you want to transfer bytes from one place to another.
When working with many of the IO-related classes in the .NET framework, you will see them having methods which accept a parameter of the type Stream. Stream is the base class for dealing with strings and it can take many forms, e.g. a MemoryStream or a FileStream, as we'll see in the next articles. However, the Stream class itself is abstract, which means that you can't instantiate it - it only serves as a common base class for the various types of streams.
Most Stream types can do three things: Read, Write and Seek (move to a new place in the stream, to either read or write from there instead of the current position). Therefore the Stream class implements three methods for deciding whether or not the derived stream class can do this: CanRead, CanWrite and CanSeek. You can always consult these properties on the stream you're working with, to make sure that your desired operation (e.g writing) is available.
A Stream should always be disposed of whenever you're done working with it. Otherwise, it might hold a lock on a resource that should not be locked anymore, e.g. a file when using a FileStream. The Stream base class implements the IDisposable interface, so releasing it is as simple as calling the Dispose() method, or perhaps even better, encapsulating the use of the stream with a using() block (that's the approach we'll use in this tutorial).
Stream Readers & Writers
A common usage of streams is as the backing source for one of the Reader or Writer classes, e.g. FileReader or BinaryWriter. You can pass your Streams to a new instances of these classes to e.g. read an entire file, manipulate it in memory and then write it back - there's a lot of possibilities. We'll see this demonstrated in the next articles as well.
A stream is basically a mechanism for moving bytes from one place to another, e.g. into a file or from a network resource. The .NET framework uses the abstract Stream class as the base for all this, offering several derived implementations of it, e.g. FileStream and MemoryStream, which we'll discuss in the next articles.