StringWriter.Close 方法

定义

关闭当前 StringWriter 流和基础流。

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

示例

此代码示例是为构造函数提供的大型示例的 StringWriter(StringBuilder) 一部分。

strWriter.Close();

// Since the StringWriter is closed, an exception will
// be thrown if the Write method is called. However,
// the StringBuilder can still manipulate the string.
strBuilder.Insert(0, "Invalid ");
Console.WriteLine(strWriter.ToString());
strWriter.Close()

' Since the StringWriter is closed, an exception will 
' be thrown if the Write method is called. However, 
' the StringBuilder can still manipulate the string.
strBuilder.Insert(0, "Invalid ")
Console.WriteLine(strWriter.ToString())

注解

有关创建文件并将文本写入文件的示例,请参阅 “如何:将文本写入文件”。 有关从文件读取文本的示例,请参阅 “如何:从文件读取文本”。 有关从二进制文件读取和写入文件的示例,请参阅 How to: Read and Write to a Newly Created Data File.

此方法重写 Stream.Close

此实现调用CloseDispose传递true值的方法。

除非显式调用 Close,否则刷新流不会刷新其基础编码器。 AutoFlush设置为true表示数据将从缓冲区刷新到流,但不会刷新编码器状态。 这使编码器能够保持其状态(部分字符),以便它可以正确编码下一个字符块。 此方案影响 UTF8 和 UTF7,其中某些字符只能在编码器接收相邻字符或字符后进行编码。

适用于

另请参阅