Essential Types C# Book

Redirect Console's input and output streams via the SetIn and SetOut methods:
using System;
class Sample
{
public static void Main()
{
System.IO.TextWriter oldOut = Console.Out;
using (System.IO.TextWriter w = System.IO.File.CreateText("e:\\output.txt"))
{
Console.SetOut(w);
Console.WriteLine("Hello world");
}
Console.SetOut(oldOut);
System.Diagnostics.Process.Start("e:\\output.txt");
}
}