日期:2014-05-17 浏览次数:20727 次
public int ID
{
get { return _ID; }
}
public string Content
{
get { return _Content; }
}
public string Title
{
get { return _Title; }
}
public string From
{
get { return _From; }
}
public DateTime AddDate
{
get { return _AddDate; }
}
public int ClsID
{
get { return _clsID; }
}
public int TmpID
{
get { return _tmpID; }
}
class Person{
private bool _sex;
private int _age;
public Person(bool sex,int age)
{
this._sex=sex;
this._age=age;
}
public bool Sex{get{return this._sex;}}//只读属性 true为男 false为女
public int Age{//可读写属性
get{
return this._age;
};
set{
this._age=value;
}
}
}
//一个人的性别在出生后应该不会变吧??(除泰国人),但是他的年龄每年都会变的吧?
//现在使用这个Person类
PerSon person=new Person(true,1);//初始化这么一个人 男人 1岁
person.Age=2;//过了一年后 你可以加一岁
//但是你不能 person.Sex=false; 你不能给他变性 应该他是只读的
------解决方案--------------------
还有1L的链接对属性的解释已经很详细了
------解决方案--------------------
面向对象的封装特性,隐藏细节。。