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

          常用鏈接

          留言簿

          隨筆分類(75)

          隨筆檔案(78)

          相冊

          實用Links

          我的Links

          搜索

          •  

          積分與排名

          • 積分 - 114328
          • 排名 - 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之間,超出這個范圍,默認設(shè)置為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);
                  }
              }
          }

          結(jié)果:
          rorely,19,Female
          posted on 2009-10-25 18:50 期待明天 閱讀(1715) 評論(0)  編輯  收藏 所屬分類: CSharp
          主站蜘蛛池模板: 六安市| 竹北市| 大关县| 青岛市| 江都市| 平罗县| 新余市| 镇平县| 吉林省| 黎川县| 富宁县| 甘泉县| 宁强县| 武山县| 加查县| 达日县| 丰台区| 光泽县| 奉贤区| 凌海市| 郎溪县| 康保县| 志丹县| 延津县| 时尚| 重庆市| 津市市| 南康市| 霍城县| 始兴县| 德州市| 娱乐| 新宁县| 玉门市| 安泽县| 长沙市| 崇信县| 周至县| 武山县| 阿克陶县| 巴彦淖尔市|