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 内のバイト オフセット。インデックス番号は 0 から始まります。

count
Int32

書き込む最大バイト数。

例外

buffernullです。

ストリームは書き込みをサポートしません。 詳細については、CanWrite のトピックを参照してください。

  • または - 現在の位置が、ストリームの末尾に向かって count バイトよりも近い位置にあり、容量を変更できません。

バッファー長から offset を差し引いた値が count より小さい値です。

offset または count が負の値です。

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います。

こちらもご覧ください

適用対象