Share via


Read Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Reads data from the NetworkStream.

Namespace:  System.Net.Sockets
Assembly:  System (in System.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

Return Value

Type: System. . :: . .Int32
The number of bytes read from the NetworkStream.

Remarks

This method reads data into the buffer parameter and returns the number of bytes successfully read. If no data is available for reading, the Read method returns 0. The Read operation reads as much data as is available, up to the number of bytes specified by the count parameter. If the remote host shuts down the connection, and all available data has been received, the Read method completes immediately and return zero bytes.

Note

Check to see if the NetworkStream is readable by calling the CanRead property. If you attempt to read from a NetworkStream that is not readable, you will get an IOException.

.NET Framework Security

See Also

Reference

NetworkStream Class

System.Net.Sockets Namespace