// 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 A { public List AllB { get; set; } } public class B { public List AllC { get; set; } } public class C { public int V { get; set; } } public class Program { public static void Main(string[] args) { A o = new A { AllB = new List { new B { AllC = new List { new C { V = 1 }, new C { V = 2 } } }, new B { AllC = new List { new C { V = 2 }, new C { V = 3 } } } } }; //List res = o.AllB.Aggregate(new List(), (aggr,b) => { aggr.AddRange(b.AllC); return aggr; }).Select(c => c.V).Distinct().ToList(); List res = o.AllB.Aggregate(new List(), (aggr,b) => aggr.Concat(b.AllC).ToList()).Select(c => c.V).Distinct().ToList(); foreach(int v in res) { Console.WriteLine(v); } } } }