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());
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())

注釈

ファイルの作成とファイルへのテキストの書き込みの例については、「 方法: ファイルにテキストを書き込む」を参照してください。 ファイルからテキストを読み取る例については、「 方法: ファイルからテキストを読み取る」を参照してください。 バイナリ ファイルの読み取りとバイナリ ファイルへの書き込みの例については、「 方法: 新しく作成されたデータ ファイルの読み取りと書き込み」を参照してください。

このメソッドは、Stream.Close をオーバーライドします。

この の Close 実装では、値を渡す Dispose メソッドが true 呼び出されます。

を明示的に呼び出 Closeさない限り、ストリームをフラッシュしても、基になるエンコーダーはフラッシュされません。 を にtrue設定AutoFlushすると、データはバッファーからストリームにフラッシュされますが、エンコーダーの状態はフラッシュされません。 これにより、エンコーダーは状態 (部分的な文字) を保持して、次の文字ブロックを正しくエンコードできるようになります。 このシナリオは UTF8 と UTF7 に影響を与え、エンコーダーが隣接する文字を受信した後にのみ特定の文字をエンコードできます。

適用対象

こちらもご覧ください