The Stream Class

The Stream class is the root of the C# stream programming. This article describe the properties and methods of this class.

The Stream class is abstract, thus it's impossible to instanciate it. But, as all the streaming classes derive from it, this class describe every functions that a streaming class should implement.

Stream class   
     Object -> Stream 
     using System.IO;
Name  Type  Description
CanRead  bool  Indicates if read operations are allowed
CanSeek  bool  Indicates if seeking is allowed on the stream
CanWrite  bool  Indicates if write operations are allowed
DataAvailable  bool  Return true if datas are available on the stream
Length  long  Length of the data available
Position  long  The current position in the stream
Prototype   Description
int Read(byte[]b, int offset, int n)   Read n bytes and store them, from the offset displacement, in the byte array b. Read return the number of bytes read or -1 if no data is available.
int ReadByte()   Read one byte from the stream and return the value of this byte. ReadByte return -1 if the end of the stream has been reached.
int Write(byte[] b, int offset, int n)   Write in the stream the n bytes from the buffer b. These bytes are written in the stream starting from the offset position.
void WriteByte(byte b)   Write byte b in the stream at the current position.
void Close()   Close the stream.
void Flush()   Force the writing of all the data that may be present in a buffer.
long Seek(long offset, SeekOrigin orig)   Set the current position in the stream. The position is given by offset, this offset may be specified from SeekOrigin.Begin (the start of the stream), SeekOrigin.Current (the current position) or SeekOrigin.End (the end of the stream)

Continue to: