Read Method
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Reads a block of bytes from the stream and writes the data in a given buffer.
Namespace: System.IO
Assembly: System.IO (in System.IO.dll)
Syntax
'Declaration
Public Overrides Function Read ( _
buffer As Byte(), _
offset As Integer, _
count As Integer _
) As Integer
public override int Read(
byte[] buffer,
int offset,
int count
)
public:
virtual int Read(
array<unsigned char>^ buffer,
int offset,
int count
) override
abstract Read :
buffer:byte[] *
offset:int *
count:int -> int
override Read :
buffer:byte[] *
offset:int *
count:int -> int
public override function Read(
buffer : byte[],
offset : int,
count : int
) : int
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.
- offset
Type: System. . :: . .Int32
The byte offset in buffer at which the read bytes will be placed.
- count
Type: System. . :: . .Int32
The maximum number of bytes to read.
Return Value
Type: System. . :: . .Int32
The total number of bytes read into the buffer. This might be less than the number of bytes requested if that number of bytes are not currently available, or zero if the end of the stream is reached.
Remarks
The offset parameter gives the offset of the byte in buffer (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.
Do not interrupt a thread that is performing a read operation. Although the application may appear to run successfully after the thread is unblocked, the interruption can decrease your application's performance and reliability.
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see dd66cd4c-b087-415f-9c3e-94e3a1835f74.