Reads a byte from the current position in the stream, or-1 if at the end of the stream.
[Visual Basic] Overridable Public Function ReadByte() As Integer [C#] public virtual int ReadByte(); [C++] public: virtual int ReadByte(); [JScript] public function ReadByte() : int;
The unsigned byte cast to an int, or-1 if at the end of the stream.
Exception Type | Condition |
---|---|
IOException | The stream is closed. |
NotSupportedException | The stream does not support reading. |
If the stream is closed or not readable, an exception will be thrown.
The implementation on Stream creates a new one-byte array and then calls Read (byte[], int,
int). While this is formally correct, it is inefficient. Any stream with an internal buffer should override this method and provide a much more efficient version that reads their buffer directly, avoiding the extra array allocation on every call.