Example

using System;
using System.IO;

namespace Samples
{
  public class StringWriterSample
  {
    public static void Main()
    {
      using(StringWriter sw = new StringWriter())
      {
        sw.Write("damien ");
        char[] chars = {'m', 'a', 'r', 'k', ' '};
        foreach(char c in chars)
          sw.Write(c);
        sw.WriteLine("brad");
        Console.WriteLine(sw);
      }
    }
  }
}
The output is
damien mark brad

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.