StringWriter enables you to write to a string synchronously or asynchronously. You can write a character at a time with the
Write or the
WriteAsync method, a string at a time using the
Write or the
WriteAsync method. In addition, you can write a character, an array of characters or a string followed by the line terminator asynchronously with one of the
WriteLineAsync methods.

Important

This type implements the
IDisposable interface. When you have finished using the type, you should dispose of it either directly or indirectly. To dispose of the type directly, call its
Dispose method in a try /catch block. To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). For more information, see the “Using an Object that Implements IDisposable” section in the
IDisposable interface topic.

The following table lists examples of other typical or related I/O tasks.