Stream.WriteByte(Byte) Stream.WriteByte(Byte) Stream.WriteByte(Byte) Stream.WriteByte(Byte) Method

定義

寫入一個位元組至資料流的目前位置,並將資料流位置推進一個位元組。Writes a byte to the current position in the stream and advances the position within the stream by one byte.

public:
 virtual void WriteByte(System::Byte value);
public virtual void WriteByte (byte value);
abstract member WriteByte : byte -> unit
override this.WriteByte : byte -> unit
Public Overridable Sub WriteByte (value As Byte)

參數

value
Byte Byte Byte Byte

寫入資料流的位元組。The byte to write to the stream.

例外狀況

發生 I/O 錯誤。An I/O error occurs.

資料流不支援寫入,或資料流已經關閉。The stream does not support writing, or the stream is already closed.

關閉資料流後呼叫了方法。Methods were called after the stream was closed.

備註

CanWrite使用屬性來判斷目前的實例是否支援寫入。Use the CanWrite property to determine whether the current instance supports writing.

給繼承者的注意事項

Stream的預設執行會建立新的單一位元組陣列, 然後呼叫Write(Byte[], Int32, Int32)The default implementation on Stream creates a new single-byte array and then calls Write(Byte[], Int32, Int32). 雖然這是正確的, 但卻沒有效率。While this is formally correct, it is inefficient. 任何具有內部緩衝區的資料流程都應該覆寫此方法,並提供更有效率的版本,以直接寫入緩衝區,避免每次呼叫都有額外的陣列配置。Any stream with an internal buffer should override this method and provide a much more efficient version that writes to the buffer directly, avoiding the extra array allocation on every call.

適用於

另請參閱