Example

using System;
using System.IO;
using System.Text;

namespace Samples
{
  public class TextWriterSample
  {
    public static void Main()
    {
      string s = "textwriter.txt";
      using(TextWriter tw = new StreamWriter(s))
      {
        DisplayInformation(tw);
        tw.WriteLine(DateTime.Now.ToString());
      }
    }
    public static void DisplayInformation(TextWriter tw)
    {
      Console.WriteLine("Encoding: {0}", tw.Encoding);
      Console.WriteLine("Format provider: {0}",
                        tw.FormatProvider);
    }
  }
}
The output is
Encoding: System.Text.UTF8Encoding
Format provider: en-AU

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.