Skip to content

Instantly share code, notes, and snippets.

@xplicit
Last active May 2, 2016 20:51
Show Gist options
  • Select an option

  • Save xplicit/fc5673cafd72022f58cde6ee24424480 to your computer and use it in GitHub Desktop.

Select an option

Save xplicit/fc5673cafd72022f58cde6ee24424480 to your computer and use it in GitHub Desktop.
using System;
using System.IO;
string result;
using (MemoryStream ms = new MemoryStream())
{
TextWriter tmp = Console.Out;
using (StreamWriter sw = new StreamWriter(ms))
{
Console.SetOut(sw);
for (int i=0;i<10;i++)
{
Console.WriteLine("1=" + i.ToString());
}
sw.Close();
Console.SetOut(tmp);
result = System.Text.Encoding.UTF8.GetString(ms.ToArray());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment