5.1.2 Using Object and Collection Initializers: Create object without object and collection initializers
parent
d848d67310
commit
93255dc698
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace automatically_implemented_properties
|
namespace automatically_implemented_properties
|
||||||
{
|
{
|
||||||
|
@ -10,11 +11,19 @@ namespace automatically_implemented_properties
|
||||||
Product myProduct = new Product();
|
Product myProduct = new Product();
|
||||||
|
|
||||||
// set the property value
|
// set the property value
|
||||||
|
myProduct.ProductID = 100;
|
||||||
myProduct.Name = "Kayak";
|
myProduct.Name = "Kayak";
|
||||||
|
myProduct.Description = "A boat for one person";
|
||||||
|
myProduct.Price = 275M;
|
||||||
|
myProduct.Category = "Watersports";
|
||||||
|
|
||||||
// get the property
|
// process the property
|
||||||
string produtName = myProduct.Name;
|
ProcessProduct(myProduct);
|
||||||
Console.WriteLine("Product name: {0}", produtName);
|
}
|
||||||
|
|
||||||
|
private static void ProcessProduct(Product prodParam)
|
||||||
|
{
|
||||||
|
// ... statements to process product in some way
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue