diff --git a/chap5_essential_language_features/essential_csharp_features/Program.cs b/chap5_essential_language_features/essential_csharp_features/Program.cs index 7da88a6..f9da1e5 100644 --- a/chap5_essential_language_features/essential_csharp_features/Program.cs +++ b/chap5_essential_language_features/essential_csharp_features/Program.cs @@ -9,8 +9,8 @@ namespace automatically_implemented_properties { static void Main(string[] args) { - // create and populate Shopping Cart - ShoppingCart cart = new ShoppingCart + // create and populate Shopping Cart, implementing IEnumerable interface + ShoppingCart products = new ShoppingCart { Products = new List { @@ -20,10 +20,22 @@ namespace automatically_implemented_properties new Product {Name = "Corner flag", Price = 34.95M} } }; + + // create and populate an array of Product objects, implementing IEnumerable interface + Product[] productArray = + { + 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(); + decimal cartTotal = products.TotalPrices(); + decimal arrayTotal = productArray.TotalPrices(); Console.WriteLine("Total: {0:c}", cartTotal); + Console.WriteLine("Array Total: {0:c}", arrayTotal); } }