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);
}
}
注意:
不能定義只讀或者只寫的屬性,必須同時提供
如果想在屬性中增加判斷、驗證等邏輯,則只能用傳統(tǒng)的屬性定義方法實現(xiàn)
新聞熱點
疑難解答
圖片精選