Export (0) Print
Expand All

MemoryStream.ReadByte Method

Reads a byte from the current stream.

[Visual Basic]
Overrides Public Function ReadByte() As Integer
public override int ReadByte();
public: int ReadByte();
public override function ReadByte() : int;

Return Value

The byte cast to a Int32, or -1 if the end of the stream has been reached.


Exception Type Condition
ObjectDisposedException The current stream instance is closed.


For an example of creating a file and writing text to a file, see Writing Text to a File. For an example of reading text from a file, see Reading Text from a File. For an example of reading from and writing to a binary file, see Reading and Writing to a Newly Created Data File.

This method overrides ReadByte.

If the read operation is successful, the current position within the stream is advanced by one byte. If an exception occurs, the current position within the stream is unchanged.


[Visual Basic, C#, C++] This code example is part of a larger example provided for the MemoryStream class.

[Visual Basic] 
' Read the remaining Bytes, Byte by Byte.
While(count < memStream.Length)
    byteArray(count) = _
    count += 1
End While

// Read the remaining bytes, byte by byte.
while(count < memStream.Length)
    byteArray[count++] = 

// Read the remaining bytes, byte by byte.
while(count < memStream->Length)
    byteArray[count++] = 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

MemoryStream Class | MemoryStream Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File

© 2014 Microsoft