我正在尝试使用CsvHelper将数据写入CSV文件。然而,我总是收到以下异常:
CsvHelper.Configuration.ConfigurationException:"继承IEnumerable的类型无法自动映射。您是否意外调用了GetRecord或WriteRecord,这些方法作用于单个记录,而没有调用作用于记录列表的GetRecords或WriteRecords?"
这是我的C#代码:
TextWriter outfile = new StreamWriter("blatest.csv");
List<string> test = new List<string>
{
"hello",
"world"
};
CsvWriter csv = new CsvWriter(outfile);
csv.WriteRecords(test);
我想将一个
List<string>
或(最好是)List<Dictionary<string,string>>
写入CSV文件。请问正确的代码是什么?我该如何设置表头呢?非常感谢您的帮助。这个问题真的让我很困扰。