Reads a sequence of bytes from the current stream and advances the current position within the stream by the number of bytes read.
[Visual Basic] Overridable Public Function Read( _ ByVal buffer() As Byte, _ ByVal offset As Integer, _ ByVal count As Integer _ ) As Integer [C#] public virtual int Read( byte[] buffer, int offset, int count ); [C++] public: virtual int Read( unsigned char* buffer[], int offset, int count ); [JScript] public function Read( buffer : Byte[], offset : int, count : int ) : int;
The total number of bytes read into the buffer. This may be less than the number of bytes requested if that many bytes aren't currently available, or zero if the end of the stream has been reached before any data can be read.
Exception Type | Condition |
---|---|
ArgumentException | The result of offset subtracted from the buffer length is less than count. |
ArgumentNullException | buffer is null. |
ArgumentOutOfRangeException | offset or count is negative. |
IOException | An I/O error occurs. |
NotSupportedException | The stream does not support reading. |
The default implementation calls the asynchronous BeginRead method.
Implementations of this method read a maximum of count bytes from the current stream and store them in buffer
beginning at offset. The current position within the stream is advanced by the number of bytes read. However, if an exception occurs, the current position within the stream is unchanged. Implementations return the number of bytes read. The return value is zero only if the position is currently at the end of the stream. The implementation will block until at least one byte of data can be read, in the event that no data is available.
Use BinaryReader for reading primitive data types.