MemoryStream.Close 方法


關閉資料流以讀取和寫入。Closes the stream for reading and writing.

 override void Close();
public override void Close ();
override this.Close : unit -> unit
Public Overrides Sub Close ()


這個程式碼範例是針對MemoryStream類別提供之較大範例的一部分。This code example is part of a larger example provided for the MemoryStream class.

End Try


這個方法覆寫 Stream.Close()This method overrides Stream.Close().

資料流程關閉MemoryStream後,仍然可以在上使用緩衝區。The buffer is still available on a MemoryStream once the stream has been closed.

除非您明確地呼叫Flush()Close, 否則清除資料流程不會排清其基礎編碼器。Flushing the stream will not flush its underlying encoder unless you explicitly call Flush() or Close. AutoFlush設定為 true 表示資料將從緩衝區排清到資料流程, 但編碼器狀態將不會排清。Setting AutoFlush to true means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. 這可讓編碼器保留其狀態 (部分字元), 以便正確地編碼下一個字元區塊。This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. 此案例會影響 UTF8 和 UTF7, 在此情況下, 只有在編碼器收到連續的字元之後, 才可以編碼特定字元。This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.

嘗試在已關閉資料流程之後操作它, 可能會擲ObjectDisposedException回。Attempting to manipulate a stream after it has been closed might throw an ObjectDisposedException.