时间:2021-01-21 10:49:02 | 栏目:.NET代码 | 点击:次
private Decimal price;
public Decimal Price
{
get
{
return price;
}
set
{
price = value;
}
}
public Product(String name, Decimal price)
{
this.price = price;
this.name = name;
}
}
public Decimal Price
{
get;
set;
}
public Product(String name, Decimal price)
{
Name = name;
Price = price;
}
public override string ToString()
{
return String.Format("{0}:{1}", this.Name, this.Price);
}
}
注意:
不能定义只读或者只写的属性,必须同时提供
如果想在属性中增加判断、验证等逻辑,则只能用传统的属性定义方法实现