MemoryStream.Close 方法
定义
关闭读写流。Closes the stream for reading and writing.
public:
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.
Finally
memStream.Close()
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.