public class Test
{
public Test(int age)
{
this.Age=age;//如果这里使用的是this.age=age;那么属性里的判断将不会执行
}
private int age;
public int Age
{
get{return age;}
set{
if(value<=18)
{
age=19;
}else
{
age=value;
}
}
}
转载于:https://www.cnblogs.com/solomon_Blog/archive/2011/07/07/2100445.html