5.1.2 Using Object and Colleciton Initializers: create object and assign value with initializer

master
Jason Zhu 2021-07-05 16:21:55 +10:00
parent 93255dc698
commit 6301eccf0a
1 changed files with 9 additions and 12 deletions

View File

@ -7,18 +7,15 @@ namespace automatically_implemented_properties
{
static void Main(string[] args)
{
// create a new Product object
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";
// process the property
ProcessProduct(myProduct);
// create a new Product object and use method on it
ProcessProduct(new Product
{
ProductID = 100,
Name = "Kayak",
Description = "A boat for one person",
Price = 275M,
Category = "Watersports"
});
}
private static void ProcessProduct(Product prodParam)