我正在使用Visual Studio 2008(C#)。有没有更好的方法来编写这段代码?我是一个可怜的程序员。更好的方式来编写这个属性和构造函数代码?
#region Properties
public string ItemCode
{
get { return _itemCode; }
set { _itemCode = value; }
}
public string ItemName
{
get { return _itemName; }
set { _itemName = value; }
}
public decimal? StockInHand
{
get { return _stockInHand; }
set { _stockInHand = value; }
}
public decimal? AlertLevelQty
{
get { return _alertLevelQty; }
set { _alertLevelQty = value; }
}
public string Unit
{
get { return _unit; }
set { _unit = value; }
}
public decimal? Discount
{
get { return _discount; }
set { _discount = value; }
}
public string WhetherInPercent
{
get { return _whetherInPercent; }
set { _whetherInPercent = value; }
}
public int CategoryID
{
get { return _categoryID; }
set { _categoryID = value; }
}
#endregion
#region Constructors
public ItemMaster()
{ }
public ItemMaster(string argItemName, string argItemCode, decimal? argStockInHand, decimal? argAlertLevelQty, string argUnit, decimal? argDiscount, string argWhetherInPercent, int argCategoryID)
{
this.ItemName = argItemName;
this.ItemCode = argItemCode;
this.StockInHand = argStockInHand;
this.AlertLevelQty = argAlertLevelQty;
this.Unit = argUnit;
this.Discount = argDiscount;
this.WhetherInPercent = argWhetherInPercent;
this.CategoryID = argCategoryID;
}
#endregion
可能没有任何问题,但只是想知道如何给它专业的触摸。 – RKh 2010-10-30 17:36:22
我更喜欢使用自动方法。它写得更干净更快。国际海事组织,尽可能保持简单。 – Kamyar 2010-10-30 17:56:30
@Kamyar:这只是一个偏好问题。在某些情况下,自动属性根本无法使用。 – Lorenzo 2010-10-30 18:00:15