1> 当不在本类中使用时,属性可以保证安全
2>属性的set和get函数可以限制字段的一些功能,以达到某种目的
pring int b{get;set;}
private int a=0; //字段
public int A //属性
{
get{return this.a;}
set
{
if(value >= 0 && value <= 100)
this.a=value;
else
throw new Exception("值的范围不合法。");
}
}
浙公网安备 33010602011771号