using System; using System.Collections.Generic; class Program { static void Main(string[] args) { Listnumbers = new List { 1, 2, 3, 4, 5 }; int sum = numbers.Sum(); Console.WriteLine("Sum of all numbers is: " + sum); } }
Sum of all numbers is: 15
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { Dictionarycart = new Dictionary { { "Book", 14.99 }, { "Shirt", 29.99 }, { "Jeans", 59.99 } }; double totalPrice = cart.Sum(item => item.Value); Console.WriteLine("Total Price of the shopping cart is: $" + totalPrice); } }
Total Price of the shopping cart is: $104.97The `Sum` method is a part of the .NET Framework library, which is installed with the .NET Runtime. The library includes various namespaces, each containing classes for different purposes. The `System.Collections.Generic` namespace is present in the `mscorlib.dll` assembly.