目前我正在使用 .Net 3.0 但我不知道如何使用 Automatic Properties 。
例如,如果我想通过 Authomatic Properties 编写此示例代码,我应该怎么做?
private string _name = string.Empty;
private string _family = string.Empty;
//A field with default value
private DateTime _releaseDate = System.DateTime.Now;
//ReadOnly Property
public string Name
{
get {return _name; }
}
//enforce validation rules on setting
public string Family
{
get { _family; }
set
{
if (value.Length < 3)
return new Exception("Family need at least 3 character long");
else
_family = value;
}
}
// A property from two other fields
public string FullName
{
get { return _name + " " + _family; }
}
谢谢大家的回复,我知道了