// 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 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, (sum, d) => sum += d.N > 0 ? d.N * d.T : d.T)); Console.WriteLine(lst.Sum((d) => d.N > 0 ? d.N * d.T : d.T)); } } }