[Quote=引用 1 楼 netwar 的回复:]
打个比方说
public class test{
public int tempAge;//这里定义的一人公共变量
private int age;
public int Age{
get{
return this.age;
}set{
if(age>100) throw Exception("年龄不能大于100");
}
}
}
打个比方说
public class test{
public int tempAge;//这里定义的一人公共变量
private int age;
public int Age{
get{
return this.age;
}set{
if(age>100) throw Exception("年龄不能大于100");
}
}
}
可以有两种方式
test a=new test();
a.tempAge=110;//这里可以直接设置,这样的话,我们就不能检查这个年龄是否正确,如果用