MemoryStream.Write 方法

定义

重载

Write(ReadOnlySpan<Byte>)

source 中包含的字节序列写入当前内存流,并按写入的字节数向前移动内存流的当前位置。

Write(Byte[], Int32, Int32)

使用从缓冲区读取的数据将字节块写入当前流。

Write(ReadOnlySpan<Byte>)

source 中包含的字节序列写入当前内存流,并按写入的字节数向前移动内存流的当前位置。

public:
 override void Write(ReadOnlySpan<System::Byte> source);
public:
 override void Write(ReadOnlySpan<System::Byte> buffer);
public override void Write (ReadOnlySpan<byte> source);
public override void Write (ReadOnlySpan<byte> buffer);
override this.Write : ReadOnlySpan<byte> -> unit
override this.Write : ReadOnlySpan<byte> -> unit
Public Overrides Sub Write (source As ReadOnlySpan(Of Byte))
Public Overrides Sub Write (buffer As ReadOnlySpan(Of Byte))

参数

sourcebuffer
ReadOnlySpan<Byte>

内存的区域。 此方法将此区域的内容复制到当前内存流。

适用于

Write(Byte[], Int32, Int32)

使用从缓冲区读取的数据将字节块写入当前流。

public:
 override void Write(cli::array <System::Byte> ^ buffer, int offset, int count);
public override void Write (byte[] buffer, int offset, int count);
override this.Write : byte[] * int * int -> unit
Public Overrides Sub Write (buffer As Byte(), offset As Integer, count As Integer)

参数

buffer
Byte[]

从中写入数据的缓冲区。

offset
Int32

buffer 中的从零开始的字节偏移量,从此处开始将字节复制到当前流。

count
Int32

最多写入的字节数。

例外

buffernull

流不支持写入。 有关其他信息,请参见 CanWrite

  • 或 - 当前位置到流结尾的距离小于 count 字节,并且无法修改容量。

缓冲区长度减去 offset 的结果小于 count

offsetcount 为负。

出现 I/O 错误。

当前流实例已关闭。

示例

此代码示例是为 MemoryStream 类提供的一个更大示例的一部分。

// Write the first string to the stream.
memStream->Write( firstString, 0, firstString->Length );
// Write the first string to the stream.
memStream.Write(firstString, 0 , firstString.Length);
' Write the first string to the stream.
memStream.Write(firstString, 0 , firstString.Length)

注解

此方法重写 Write

offset 参数提供从中 buffer 写入的第一个字节的偏移量,并且该 count 参数提供要写入的字节数。 如果写入操作成功,则流中的当前位置由写入的字节数进行高级。 如果发生异常,则流中的当前位置保持不变。

除了使用 byte[] 参数构造的MemoryStream构造外,在展开MemoryStream的末尾MemoryStream写入操作。

另请参阅

适用于