Freigeben über


UnmanagedMemoryStream.Read Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.

Reads the specified number of bytes into the specified array.

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

Syntax

'Declaration
<SecuritySafeCriticalAttribute> _
Public Overrides Function Read ( _
    <OutAttribute> buffer As Byte(), _
    offset As Integer, _
    count As Integer _
) As Integer
[SecuritySafeCriticalAttribute]
public override int Read(
    byte[] buffer,
    int offset,
    int count
)

Parameters

  • buffer
    Type: array<System.Byte[]
    When this method returns, contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source. This parameter is passed uninitialized.
  • 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 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.

Exceptions

Exception Condition
ObjectDisposedException

The stream is closed.

NotSupportedException

The underlying memory does not support reading.

- or -

The CanRead property is set to false.

ArgumentNullException

The buffer parameter is set to nulla null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

The offset parameter is less than zero.

- or -

The count parameter is less than zero.

ArgumentException

The length of the buffer array minus the offset parameter is less than the count parameter.

Remarks

The offset parameter gives the offset of the byte in the array parameter (the buffer index) at which to begin reading, and the count parameter gives the maximum number of bytes to be read from this stream. The returned value is the actual number of bytes read, or zero if the end of the stream is reached. If the read operation is successful, the current position of the stream is advanced by the number of bytes read. If an exception occurs, the current position of the stream is unchanged.

The Read method returns zero only after reaching the end of the stream. Otherwise, Read always reads at least one byte from the stream before returning. If no data is available from the stream upon a call to Read, the method will block until at least one byte of data can be returned. An implementation is free to return fewer bytes than requested even if the end of the stream has not been reached.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.