2021-07-05 15:05:57 +10:00
|
|
|
|
using System;
|
2021-07-05 15:54:28 +10:00
|
|
|
|
using System.Diagnostics;
|
2021-07-05 15:05:57 +10:00
|
|
|
|
|
|
|
|
|
namespace automatically_implemented_properties
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2021-07-05 16:21:55 +10:00
|
|
|
|
// 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"
|
|
|
|
|
});
|
2021-07-05 15:54:28 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ProcessProduct(Product prodParam)
|
|
|
|
|
{
|
|
|
|
|
// ... statements to process product in some way
|
2021-07-05 15:05:57 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|