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.

適用於

另請參閱