- - CSV, , . CSV, , , .
Dictionary<string, List<string>>, , , - :
using System.IO;
using System.Collections.Generic;
using Ctl.Data;
static IEnumerable<Dictionary<string, List<string>>> ReadCsv(string filePath)
{
using (StreamReader sr = new StreamReader(filePath))
{
CsvReader csv = new CsvReader(sr);
if (!csv.Read())
{
yield break;
}
RowValue header = csv.CurrentRow;
while (csv.Read())
{
Dictionary<string, List<string>> dict =
new Dictionary<string, List<string>>(header.Count);
RowValue record = csv.CurrentRow;
for (int i = 0; i < record.Count; ++i)
{
string headerValue = (i < header.Count ? header[i].Value : null)
?? string.Empty;
List<string> list;
if (!dict.TryGetValue(headerValue, out list))
{
dict[headerValue] = list = new List<string>();
}
list.Add(record[i].Value);
}
yield return dict;
}
}
}
Lumenworks - Ctl.Data, , , JSON , . ( : Ctl.Data)