Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a TextWriter for the console

Tags:

c#

.net

csvhelper

I am using CsvHelper, which uses a TextWriter to write its output. Instead of writing to a file, I would like to write the contents to the console. How can I get a TextWriter that will write to the console?

like image 258
Ryan Kohn Avatar asked Nov 04 '14 15:11

Ryan Kohn


1 Answers

Use the Console.Out property to get the TextWriter for the console, like so:

var textWriter = Console.Out;

using (var csvWriter = new CsvWriter(textWriter))
{
    csvWriter.WriteRecords(records);
    textWriter.Flush();
}
like image 145
Ryan Kohn Avatar answered Oct 10 '22 15:10

Ryan Kohn