隨筆 - 78  文章 - 25  trackbacks - 0
          <2009年10月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿

          隨筆分類(75)

          隨筆檔案(78)

          相冊

          實用Links

          我的Links

          搜索

          •  

          積分與排名

          • 積分 - 114345
          • 排名 - 515

          最新評論

          閱讀排行榜

          評論排行榜

          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;

          namespace useClass2
          {
              
          public enum Genders { Female=0,Male=1}
              
          public class Person {
                  
          /// <summary>
                  /// _name is private field,Name is public attribute,姓名前后的空去除掉
                  /// </summary>
                  private string _name;
                  
          public string Name {
                      get { 
          return this._name; }
                      set { 
          this._name = value.Trim(); }
                  }
                  
          /// <summary>
                  /// _age:1-120之間,超出這個范圍,默認設置為20
                  /// </summary>
                  private int _age;
                  
          public int Age {
                      get { 
          return this._age; }
                      set {
                          
          if ((value > 120|| (value < 1)) this._age = 20;
                          
          else this._age = value;
                      }
                  }
                  
          /// <summary>
                  /// _gender
                  /// </summary>
                  private Genders _gender;
                  
          public Genders Gender {
                      get { 
          return this._gender; }
                      set { 
          this._gender = value; }
                  }
              }
              
          class Program
              {
                  
          static void Main(string[] args)
                  {
                      Person aPerson 
          = new Person();
                      aPerson.Name 
          = "Rorely";
                      aPerson.Age 
          = 19;
                      aPerson.Gender 
          = Genders.Female;
                      PrintPerson(aPerson);
                      System.Console.ReadLine();
                  }
                  
          static void PrintPerson(Person a) {
                      System.Console.WriteLine(
          "{0},{1},{2}",a.Name,a.Age,a.Gender);
                  }
              }
          }

          結果:
          rorely,19,Female
          posted on 2009-10-25 18:50 期待明天 閱讀(1715) 評論(0)  編輯  收藏 所屬分類: CSharp
          主站蜘蛛池模板: 铜梁县| 女性| 喀喇沁旗| 修水县| 深圳市| 虎林市| 宜州市| 衢州市| 台江县| 尖扎县| 林口县| 郧西县| 泸西县| 运城市| 张家港市| 阳东县| 独山县| 吉木乃县| 阿拉善右旗| 毕节市| 监利县| 汝州市| 闽清县| 依兰县| 平罗县| 浦北县| 会昌县| 南投县| 远安县| 天津市| 仁寿县| 依安县| 吉隆县| 烟台市| 曲靖市| 耿马| 土默特左旗| 汉阴县| 海宁市| 资兴市| 蒙自县|