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.

如果讀取作業成功,資料流程中目前的位置會由一個位元組來前移。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.

適用於

另請參閱