1
我想驗證一個null屬性,並且想返回一個空字符串(如果它爲NULL)。對於我創建了一個類象下面這樣:返回之前驗證null屬性
public class TestValue
{
public string CcAlias
{
get
{
return string.IsNullOrEmpty(CcAlias) ? string.Empty : CcAlias;
}
set
{
CcAlias = CcAlias ?? string.Empty;
}
}
}
並測試了我的類下面的代碼:
System.StackOverflowException was unhandled
HResult=-2147023895
Message=Exception of type 'System.StackOverflowException' was thrown.
InnerException:
如果您正在執行任何自定義代碼,則不能使用自動屬性。在自定義功能的情況下(就像你正在做的那樣),你必須自己實現屬性的代碼(包括存儲和檢索來自成員變量的值)。 –