TextWriter.Close 方法

定义

关闭当前编写器并释放任何与该编写器关联的系统资源。Closes the current writer and releases any system resources associated with the writer.

public:
 virtual void Close();
public virtual void Close ();
abstract member Close : unit -> unit
override this.Close : unit -> unit
Public Overridable Sub Close ()

注解

此实现Close TextWriter.Dispose(Boolean)调用方法并向其传递一个true值。This implementation of Close calls the TextWriter.Dispose(Boolean) method and passes it a true value.

除非显式调用FlushClose, 否则刷新流将不会刷新其基础编码器。Flushing the stream will not flush its underlying encoder unless you explicitly call Flush or Close. true如果将StreamWriter.AutoFlush属性设置为,则表示数据将从缓冲区刷新到流,但编码器状态不会被刷新。Setting the StreamWriter.AutoFlush property 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 be encoded only after the encoder receives the adjacent character or characters.

备注

在派生类中,不要重写Close方法。In derived classes, do not override the Close method. 相反,重写TextWriter.Dispose(Boolean)方法以添加用于释放资源的代码。Instead, override the TextWriter.Dispose(Boolean) method to add code for releasing resources.

适用于

另请参阅