CSV to object model mapping

后端 未结 6 665
礼貌的吻别
礼貌的吻别 2020-12-01 07:51

I have a CSV file that I want to read into a List. Here\'s an example file:

Plant,Material,\"Density, Lb/ft3\",Storage Location
FRED,10000477,64.3008,3300
F         


        
6条回答
  •  爱一瞬间的悲伤
    2020-12-01 08:05

    It doesn't use LINQ but CsvHelper is a simple method to implement CSV parsing to a .NET object:

    using (TextReader txt = new StreamReader(filename))
    {
        using (var csv = new CsvReader(txt))
        {
            var records = csv.GetRecords();
            return records.ToList();
        }
    }
    

提交回复
热议问题