In general LINQ is a good option to do this. Have a look here where at the begin a Non-LINQ approach for grouping the data is introduced