From 3b938d8c616858dbfff9bcb0d1701bfbc47e9cf8 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Mon, 12 Jul 2021 11:15:27 +1000 Subject: [PATCH] 5.1.4 Applying Extension Methods to an Interface --- .../essential_csharp_features/Program.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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); } }