Linq to CSV select by column

Posted by griegs on Stack Overflow See other posts from Stack Overflow or by griegs
Published on 2011-01-05T23:47:52Z Indexed on 2011/01/05 23:54 UTC
Read the original article Hit count: 131

Filed under:

If I have the following (sample) text file;

year,2008,2009,2010
income,1000,1500,2000
dividends,100,200,300
net profit,1100,1700,2300
expenses,500,600,500
profit,600,1100,1800

Is there a way in Linq that I can select the expenses for 2010 only?

So far I have the following which gets me all the data;

        var data = File.ReadAllLines(fileName)
            .Select( 
                l => {
                    var split = l.CsvSplit();
                    return split;
                }
            );

        foreach (var item in data)
            Console.WriteLine("{0}: ${1}", item[0], item[1]);

© Stack Overflow or respective owner

Related posts about LINQ