Listnumbers = new List { 4, 2, 6, 8, 1 }; int sum = numbers.Sum(); Console.WriteLine(sum); // 21
class Item { public int Value { get; set; } } ListIn this example, we create a List of Item objects, each containing a Value property. We then use the Sum function with a lambda expression to calculate the sum of all the Value properties. Package library: iTextSharp.outer or iTextSharp.xtra libraries.- items = new List
- { new Item { Value = 4 }, new Item { Value = 2 }, new Item { Value = 6 }, new Item { Value = 8 }, new Item { Value = 1 }, }; int sum = items.Sum(item => item.Value); Console.WriteLine(sum); // 21