Get TextWriter for Console

I am using CsvHelper

which uses TextWriter

to write my output. Instead of writing to a file, I would like to write the content to the console. How can I get TextWriter

that to write to the console?

+3


source to share


1 answer


Use property Console.Out

to get TextWriter

to console like:



var textWriter = Console.Out;

using (var csvWriter = new CsvWriter(textWriter))
{
    csvWriter.WriteRecords(records);
    textWriter.Flush();
}

      

+9


source







All Articles