2021-07-05 15:05:57 +10:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
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.Name = "Kayak";
|
|
|
|
|
|
|
|
|
|
// get the property
|
|
|
|
|
string produtName = myProduct.Name;
|
|
|
|
|
Console.WriteLine("Product name: {0}", produtName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Product
|
|
|
|
|
{
|
|
|
|
|
private string name;
|
2021-07-05 15:38:10 +10:00
|
|
|
|
|
|
|
|
|
public int ProductID { get; set; }
|
2021-07-05 15:05:57 +10:00
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
2021-07-05 15:38:10 +10:00
|
|
|
|
get { return ProductID + name; }
|
2021-07-05 15:05:57 +10:00
|
|
|
|
set { name = value; }
|
|
|
|
|
}
|
2021-07-05 15:38:10 +10:00
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
public decimal Price { get; set; }
|
|
|
|
|
public string Category { set; get; }
|
2021-07-05 15:05:57 +10:00
|
|
|
|
}
|
|
|
|
|
}
|