MemoryStream.ReadByte 方法

定义

从当前流中读取一个字节。Reads a byte from the current stream.

public:
 override int ReadByte();
public override int ReadByte ();
override this.ReadByte : unit -> int
Public Overrides Function ReadByte () As Integer

返回

强制转换为 Int32 的字节;或者如果已到达流的末尾,则为 -1。The byte cast to a Int32, or -1 if the end of the stream has been reached.

异常

当前流实例已关闭。The current stream instance is closed.

示例

此代码示例是为 MemoryStream 类提供的更大示例的一部分。This code example is part of a larger example provided for the MemoryStream class.

// Read the remaining bytes, byte by byte.
while ( count < memStream->Length )
{
   byteArray[ count++ ] = Convert::ToByte( memStream->ReadByte() );
}
// Read the remaining bytes, byte by byte.
while(count < memStream.Length)
{
    byteArray[count++] =
        Convert.ToByte(memStream.ReadByte());
}
' Read the remaining Bytes, Byte by Byte.
While(count < memStream.Length)
    byteArray(count) = _
        Convert.ToByte(memStream.ReadByte())
    count += 1
End While

注解

此方法重写 ReadByteThis method overrides ReadByte.

如果读取操作成功,则流中的当前位置将以1个字节为高级。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.

适用于

另请参阅