From 93255dc698f69100c708a5c8ee810abd74ce6112 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Mon, 5 Jul 2021 15:54:28 +1000 Subject: [PATCH] 5.1.2 Using Object and Collection Initializers: Create object without object and collection initializers --- .../Program.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/chap5_essential_language_features/automatically_implemented_properties/Program.cs b/chap5_essential_language_features/automatically_implemented_properties/Program.cs index c58a3da..4b00042 100644 --- a/chap5_essential_language_features/automatically_implemented_properties/Program.cs +++ b/chap5_essential_language_features/automatically_implemented_properties/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; namespace automatically_implemented_properties { @@ -10,11 +11,19 @@ namespace automatically_implemented_properties Product myProduct = new Product(); // set the property value + myProduct.ProductID = 100; myProduct.Name = "Kayak"; + myProduct.Description = "A boat for one person"; + myProduct.Price = 275M; + myProduct.Category = "Watersports"; - // get the property - string produtName = myProduct.Name; - Console.WriteLine("Product name: {0}", produtName); + // process the property + ProcessProduct(myProduct); + } + + private static void ProcessProduct(Product prodParam) + { + // ... statements to process product in some way } }