5.1.2 Using Object and Collection Initializers: Create object without object and collection initializers

master
Jason Zhu 2021-07-05 15:54:28 +10:00
parent d848d67310
commit 93255dc698
1 changed files with 12 additions and 3 deletions

View File

@ -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
}
}