45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
|
|
namespace automatically_implemented_properties
|
|
{
|
|
class Program
|
|
{
|
|
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);
|
|
}
|
|
|
|
private static void ProcessProduct(Product prodParam)
|
|
{
|
|
// ... statements to process product in some way
|
|
}
|
|
}
|
|
|
|
public class Product
|
|
{
|
|
private string name;
|
|
|
|
public int ProductID { get; set; }
|
|
|
|
public string Name
|
|
{
|
|
get { return ProductID + name; }
|
|
set { name = value; }
|
|
}
|
|
public string Description { get; set; }
|
|
public decimal Price { get; set; }
|
|
public string Category { set; get; }
|
|
}
|
|
} |