Stream.WriteByte(Byte) 方法

定义

将一个字节写入流内的当前位置,并将流内的位置向前提升一个字节。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

要写入流中的字节。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.

适用于

另请参阅