111,059
社区成员




class A
{
string pwd;
public event EventHandler PasswordChanging;
public string Pwd
{
get { return pwd; }
private set
{
if (string.IsNullOrEmpty(value) )
{
throw new ArgumentException("password cannot be empty");
}
if (pwd != value)
{
if (PasswordChanging != null) PasswordChanging(this, EventArgs.Empty);
}
pwd = value;
}
}
void Test()
{
this.pwd = "abc"; // 直接赋值,什么额外事情都不会发生
this.Pwd = "efg"; // 可以引发密码更改事件,可以进行校验
}
}