[英]CsvWriter, CS1503 Argument 2: cannot convert CultureInfo
I'm using CsvHelper (great package thanks Josh) and having problems with the constructor with.Net Core when using CultureInfo.我正在使用 CsvHelper(很棒的软件包,感谢 Josh),并且在使用 CultureInfo 时遇到构造函数 with.Net Core 的问题。
Josh's example has something like this... (from https://joshclose.github.io/CsvHelper/examples/writing/write-class-objects )乔什的例子有这样的东西......(来自https://joshclose.github.io/CsvHelper/examples/writing/write-class-objects )
using (var writer = new StreamWriter("path\\to\\file.csv"))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
csv.WriteRecords(records);
}
However, that gives me, CS1503 Argument 2: cannot convert from 'System.Globalization.CultureInfo' to 'CsvHelper.Configuration.Configuration'但是,这给了我 CS1503 参数 2:无法从“System.Globalization.CultureInfo”转换为“CsvHelper.Configuration.Configuration”
so, I need to do this instead所以,我需要这样做
using (var writer = new StreamWriter("path\\to\\file.csv"))
using (var csv = new CsvWriter(writer: writer ))
{
csv.Configuration.CultureInfo = CultureInfo.InvariantCulture ;
csv.WriteRecords(records);
}
Is Josh's example wrong or am I doing something wrong?乔什的例子是错误的还是我做错了什么?
Josh's example works with the current CsvHelper, Version 13.0.0 Josh 的示例适用于当前的 CsvHelper,版本 13.0.0
using (var writer = new StreamWriter("path\\to\\file.csv"))
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
{
csv.WriteRecords(records);
}
Before Version 13.0.0, your example works.在版本 13.0.0 之前,您的示例有效。
using (var writer = new StreamWriter("path\\to\\file.csv"))
using (var csv = new CsvWriter(writer))
{
csv.Configuration.CultureInfo = CultureInfo.InvariantCulture;
csv.WriteRecords(records);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.