I need to take
Console.WriteLine()
FileStream
var fs = new FileStream("dataOut.txt", FileMode.Create);
var sw = new StreamWriter(fs);
Console.SetOut(sw);
Console.SetError(sw);
Console.WriteLine("whatever")
string outString = "";
Console.SetOut(outString);
Console.SetError(outString);
Use a StringWriter
:
var sw = new StringWriter();
Console.SetOut(sw);
Console.SetError(sw);
string result = sw.ToString();