简体   繁体   English

获取控制台的TextWriter

[英]Get a TextWriter for the console

I am using CsvHelper , which uses a TextWriter to write its output. 我正在使用CsvHelper ,它使用TextWriter来编写其输出。 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? 如何获得将写入控制台的TextWriter

Use the Console.Out property to get the TextWriter for the console, like so: 使用Console.Out属性获取控制台的TextWriter ,如下所示:

var textWriter = Console.Out;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM