// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.Collections.Generic; using System.Linq; public class Count13 { public class Data { public int Iv { get; set; } public string Sv { get; set; } } public static void Main(string[] args) { List lst = new List { new Data { Iv = 1, Sv = "A" }, new Data { Iv = 2, Sv = "B" }, new Data { Iv = 2, Sv = "C" }, new Data { Iv = 2, Sv = "D" }, new Data { Iv = 3, Sv = "E" }, new Data { Iv = 3, Sv = "F" } }; var res = lst.CountBy(o => o.Iv).OrderBy(e => -e.Value); foreach(var e in res) { Console.WriteLine("{0} {1}", e.Key, e.Value); } } }