using System; using System.Collections.Generic; using System.Diagnostics; using automatically_implemented_properties; namespace automatically_implemented_properties { class Program { static void Main(string[] args) { // create and populate Shopping Cart ShoppingCart cart = new ShoppingCart { Products = new List { new Product {Name = "Kayak", Price = 275M}, new Product {Name = "Lifejacket", Price = 48.95M}, new Product {Name = "Soccer ball", Price = 19.50M}, new Product {Name = "Corner flag", Price = 34.95M} } }; // get total value of the products in cart decimal cartTotal = cart.TotalPrices(); Console.WriteLine("Total: {0:c}", cartTotal); } } public static class MyExtensionMethod { public static decimal TotalPrices(this ShoppingCart cartParam) { decimal total = 0; foreach (Product prod in cartParam.Products) { total += prod.Price; } return total; } } }