แก้ไข

แชร์ผ่าน


MemoryStream.Close Method

Definition

Closes the stream for reading and writing.

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

Examples

This code example is part of a larger example provided for the MemoryStream class.

Finally
    memStream.Close()
End Try

Remarks

This method overrides Stream.Close().

The buffer is still available on a MemoryStream once the stream has been closed.

Flushing the stream will not flush its underlying encoder unless you explicitly call Flush() or Close. 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. This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.

Attempting to manipulate a stream after it has been closed might throw an ObjectDisposedException.

Applies to

See also