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.

适用于

另请参阅