// 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 Data { public int N { get; set; } public int T { get; set; } } public class Program { public static int MyAggregate(int sum, Data d) { return sum += d.N > 0 ? d.N * d.T : d.T; } public static int MySum(Data d) { return d.N > 0 ? d.N * d.T : d.T; } public static void Main(string[] args) { List lst = new List { new Data { N=0, T=1 }, new Data { N=2, T=3 } }; Console.WriteLine(lst.Aggregate(0, MyAggregate)); Console.WriteLine(lst.Sum((Func)MySum)); } } }