I am having a csv file like this
A, 22, 23, 12
B, 32, 4, 33
C, 34, 3 ,33
I want to print the sum and average of each row and skip the first
Something like this maybe:
var csv = @"A, 22, 23, 12
B, 32, 4, 33
C, 34, 3 ,33";
var lines =
csv.Split('\n').Select(x => x.Split(',').Skip(1).Select(n => int.Parse(n))).Select(x => new {Sum = x.Sum(), Average = x.Average()});
foreach (var line in lines)
{
Console.WriteLine("Sum: " + line.Sum);
Console.WriteLine("Average: " + line.Average);
}
In general, I don't suggest to do something like this. You should use a full blown CSV reader to parse the CSV file and you should include error handling.