In diesem Beitrag möchte ich Anregungen geben, wie man effektiv mit LINQ-Queries arbeiten kann.
public static string[] CSV_CONTENT =new string[] { "Datum;Name;Distanz", "1.1.2015;Ca;200", "2.1.2015;We;300", "2.1.2015;We;100", "2.1.2015;Ca;150", "12.2.2015;Ca;50", }; static void ParseCSV() { // Skip Header: IEnumerable<string> rowsWithContent = CSV_CONTENT.Skip(1); // Split rows into columns: IEnumerablee<string[]> data = rowsWithContent.Select(x => x.Split(';')); // Filter all wrong rows: IEnumerablee<string[]> correctData = data.Where(row => row.Length == 3 && row.All(cell=>!string.IsNullOrEmpty(cell))); //Generate Datastructure: var richData=correctData.Select(row=> new { DatePoint=DateTime.Parse(row[0]), Name=row[1], Distance=uint.Parse(row[2]) }); // Read out data: Console.WriteLine("Total Minimum: {0} | Total Maximum: {1}", richData.Min(x => x.Distance), richData.Max(x => x.Distance)); var personResults = richData.GroupBy(x =>? x.Name); foreach (var item in personResults) { Console.WriteLine("Result of: " + item.Key); Console.WriteLine(" First entry: " + item.Min(x => x.DatePoint)); Console.WriteLine(" Last entry: " + item.Max(x => x.DatePoint)); Console.WriteLine(" Total distance: " + item.Sum(x => x.Distance)); } }