MemoryStream.Write 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
| 名稱 | Description |
|---|---|
| Write(ReadOnlySpan<Byte>) |
將 所 |
| Write(Byte[], Int32, Int32) |
利用從緩衝區讀取的資料,將一個位元組區塊寫入當前串流。 |
Write(ReadOnlySpan<Byte>)
將 所 source 包含的位元組序列寫入目前記憶體串流,並依照寫入的位元組數將該記憶體串流中的當前位置往前推進。
public:
override void Write(ReadOnlySpan<System::Byte> buffer);
public:
override void Write(ReadOnlySpan<System::Byte> source);
public override void Write(ReadOnlySpan<byte> buffer);
public override void Write(ReadOnlySpan<byte> source);
override this.Write : ReadOnlySpan<byte> -> unit
override this.Write : ReadOnlySpan<byte> -> unit
Public Overrides Sub Write (buffer As ReadOnlySpan(Of Byte))
Public Overrides Sub Write (source 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
最大可寫入位元組數。
例外狀況
buffer 是 null。
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。
參數 offset 表示要寫入的第一個位元組 buffer 的偏移量, count 參數則表示要寫入的位元組數。 若寫入成功,當前在串流中的位置會依照寫入的位元組數前進。 若發生例外,串流中目前位置不變。
除了構造中帶有位元組[]參數外,將MemoryStream寫入在展開MemoryStream的末尾MemoryStream的操作。