日期:2014-05-17  浏览次数:20606 次

请问下面这段代码什么意思 主要是干什么用的 我在很多地方都看到过
C# code

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; }
              }


有时候还会出现什么get什么 set什么之类的形式 他们到底是什么 用来做什么用的 能给个例子看看最好了

------解决方案--------------------
http://hi.baidu.com/panjundao/blog/item/319d5adb0e6aa03833fa1c98.html
------解决方案--------------------
面向对象三大机制:
封装:您所用的就是封装!
继承!
多态!
------解决方案--------------------
封装 OOP没学好
------解决方案--------------------
他是类的属性
比如说你有一个叫“人”的类
他有一些基本的属性吧?比如性别,年龄
C# code

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的链接对属性的解释已经很详细了
------解决方案--------------------
面向对象的封装特性,隐藏细节。。