Stream.Read Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)


Public MustOverride Function Read ( _
    buffer As Byte(), _
    offset As Integer, _
    count As Integer _
) As Integer
public abstract int Read(
    byte[] buffer,
    int offset,
    int count


  • buffer
    Type: array<System..::.Byte>[]()[]
    An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.
  • offset
    Type: System..::.Int32
    The zero-based byte offset in buffer at which to begin storing the data read from the current stream.
  • count
    Type: System..::.Int32
    The maximum number of bytes to be read from the current stream.

Return Value

Type: System..::.Int32
The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.


Exception Condition

The sum of offset and count is larger than the buffer length.


buffer is nullNothingnullptra null reference (Nothing in Visual Basic).


offset or count is negative.


An I/O error occurs.


The stream does not support reading.


Methods were called after the stream was closed.


Use the CanRead property to determine whether the current instance supports reading.

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 remains 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. Read returns 0 only when there is no more data in the stream and no more is expected (such as a closed socket or end of file). An implementation is free to return fewer bytes than requested even if the end of the stream has not been reached.

Use BinaryReader for reading primitive data types.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0


Windows Phone

See Also


Stream Class

System.IO Namespace