// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections.Generic; using System.Linq; namespace E { public class X { public string MasterID { get; set; } public int Version { get; set; } } public class Program { public static void Main(string[] args) { List tbl = new List(); tbl.Add(new X { MasterID="ABC", Version=1 }); tbl.Add(new X { MasterID="ABC", Version=2 }); tbl.Add(new X { MasterID="DEF", Version=1 }); tbl.Add(new X { MasterID="HIJ", Version=1 }); tbl.Add(new X { MasterID="HIJ", Version=2 }); tbl.Add(new X { MasterID="HIJ", Version=3 }); IEnumerable q = from row in tbl where row.Version == tbl.Where(r => r.MasterID == row.MasterID).Select(r => r.Version).Max() select row; foreach(X o in q) { Console.WriteLine(o.MasterID + " " + o.Version); } } } }