Skip to content

"DataAvailable" property referred to but not used in code example #10896

Closed
@robertpba

Description

@robertpba

Type of issue

Other (describe below)

Description

In the Examples section, the following sentence refers to the use of the DataAvailable property, however the shown code does not use the DataAvailable property.

The following code example uses DataAvailable to determine if data is available to be read. If data is available, it reads from the NetworkStream.

byte[] myReadBuffer = new byte[1024];
StringBuilder myCompleteMessage = new StringBuilder();
int numberOfBytesRead = myNetworkStream.Read(myReadBuffer, 0, myReadBuffer.Length);

// Read all the data until the end of stream has been reached.
// The incoming message may be larger than the buffer size.
while (numberOfBytesRead > 0)
{
    myCompleteMessage.Append(Encoding.ASCII.GetString(myReadBuffer, 0, numberOfBytesRead));
    numberOfBytesRead = myNetworkStream.Read(myReadBuffer, 0, myReadBuffer.Length);
}

// Print out the received message to the console.
Console.WriteLine("You received the following message : " + myCompleteMessage);

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.net.sockets.networkstream.read?view=net-9.0#system-net-sockets-networkstream-read(system-byte()-system-int32-system-int32)

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Net.Sockets/NetworkStream.xml

Document Version Independent Id

b40c2ef4-b8a0-8de3-e71d-baf1aaae541b

Article author

@karelz

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions