private string OrderNO { get; set; }
突然要用到傳統寫法,反而遇到問題private string OrderNO
{
get { return this.OrderNO.Trim(); }
set
{
if (string.IsNullOrEmpty(value))
throw new Exception("沒有派工單號無法執行");
this.OrderNO = value;
}
}
上述寫法 Setter 部分會變成無窮迴圈,直到拋出 StackOverflowException,要改成下述寫法才可以正常使用
private string _OrderNO
public string OrderNO
{
get { return this._OrderNO.Trim(); }
set
{
if (string.IsNullOrEmpty(value))
throw new Exception("沒有派工單號無法執行");
this._OrderNO = value;
}
}

沒有留言:
張貼留言