title: Redirect Console.WriteLine() output to string
body: <p>I need to take <code>Console.WriteLine()</code> output, and append to a string. I cannot change the Main method to simply append to a string instead of writing to console - I need a method to read all written lines from the console and append them to a string. </p>
  
  <p>Currently, I have been using a <code>FileStream</code> and redirecting console output into a text file, and then reading from that.</p>
  
  <pre><code>var fs = new FileStream("dataOut.txt", FileMode.Create);
  var sw = new StreamWriter(fs);
  Console.SetOut(sw);
  Console.SetError(sw);
  </code></pre>
  
  <p>And then <code>Console.WriteLine("whatever")</code> writes to the text file. However, I would like to do this without going back and forth from a text file.</p>
  
  <p>Is something like this possible? I realize that the example below does not.</p>
  
  <pre><code>string outString = "";
  Console.SetOut(outString);
  Console.SetError(outString);
  </code></pre>