safaribook-pro-aspnet-mvc3/chap5_essential_language_fe.../automatically_implemented_p.../Program.cs

36 lines
876 B
C#
Raw Normal View History

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; }
public string Name
{
2021-07-05 15:38:10 +10:00
get { return ProductID + name; }
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; }
}
}