With the code below, on the foreach, I get an exception.
I place breakpoint on the csv (second line), I expand the result, I see 2 entries thats ok.
When I do the same on the csv in the foreach, I get an excpetion : can't read from closed text reader.
Any idea ?
Thanks,
My CSV file :
A0;A1;A2;A3;A4 B0;B1;B2;B3;B4 The code
var lines = File.ReadLines("filecsv").Select(a => a.Split(';')); IEnumerable<IEnumerable<MyClass>> csv = from line in lines select (from piece in line select new MyClass { Field0 = piece[0].ToString(), Field1 = piece[1].ToString() } ).AsEnumerable<MyClass>(); foreach (MyClass myClass in csv) Console.WriteLine(myClass.Field0); Console.ReadLine(); MyClass :
public class MyClass { public string Field0 { get; set; } public string Field1 { get; set; } }