1,你代码中 getAge 和setAge 两个方法 和 public int Age{set;get;}是一模一样的效果
2、set是属性的写,get是读,需求决定了写法。
比如希望只读,就要分开写了
private int age;
public int Age{
get { return age; }
private set { age= value; } //只能在类内部写入
}
而希望暴漏整个属性则可以简单的写
public int Age{set;get;}
常用的就是以上两种。
Name是带有属性访问器的属性,而字段age是通过两个方法函数,功能上一样。