See Also: Stream Members
Streams involve three fundamental operations:
All classes that represent streams inherit from the System.IO.Stream class. The System.IO.Stream class and its subclasses provide a generic view of data sources and repositories, isolating the programmer from the specific details of the operating system and underlying devices.
Subclasses are required to provide implementations only for the synchronous read and write methods. The asynchronous read and write methods are implemented via the synchronous ones.
Depending on the underlying data source or repository, streams might support only some of these capabilities. An application can query a stream for its capabilities by using the Stream.CanRead, Stream.CanWrite, and Stream.CanSeek properties.
The Stream.Read(Byte, int, int) and Stream.Write(Byte, int, int) methods read and write data in a variety of formats. For streams that support seeking, the Stream.Seek(long, SeekOrigin) and Stream.SetLength(long) methods, and the Stream.Position and Stream.Length properties can be used to query and modify the current position and length of a stream.
Some stream implementations perform local buffering of the underlying data to improve performance. For such streams, the Stream.Flush method can be used to clear any internal buffers and ensure that all data has been written to the underlying data source or repository.
Calling Stream.Close on a System.IO.Stream flushes any buffered data, essentially calling Stream.Flush for you. Stream.Close also releases operating system resources such as file handles, network connections, or memory used for any internal buffering.