http://www.aygfsteel.com/ebecket 返還網(wǎng)
          隨筆-140  評(píng)論-11  文章-131  trackbacks-0
          C#]Enum枚舉類型使用總結(jié)
          public enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };

          The entries of the Colors Enum are:
          Red
          Green
          Blue
          Yellow


          根據(jù)name獲得Enum的類型:
          Colors mycolor = (Colors)Enum.Parse(typeof(Colors),"red",true);
          (int)mycolor1=1
          mycolor1.GetTypeCode=Int32


          根據(jù)value獲得Enum的類型:
          Colors mycolor = (Colors)Enum.Parse(typeof(Colors),"1",true);
          mycolor2.ToString()=Red
          mycolor2.GetTypeCode=Int32


          遍歷枚舉內(nèi)容
          foreach(string s in Enum.GetNames(typeof(Colors)))
          {
          //to do
          }


          Colors myOrange = (Colors)Enum.Parse(typeof(Colors), "Red, Blue,Yellow");
          The myOrange value has the combined entries of [myOrange.ToString()]=13


          Colors myOrange2 = (Colors)Enum.Parse(typeof(Colors), "Red, Blue");
          The myOrange2 value has the combined entries of [myOrange2.ToString()]=5
          posted on 2009-11-20 17:49 becket_zheng 閱讀(684) 評(píng)論(0)  編輯  收藏 所屬分類: C#
          主站蜘蛛池模板: 大同市| 化德县| 银川市| 托克托县| 长沙县| 隆子县| 仁化县| 墨江| 会昌县| 罗田县| 赤峰市| 湘阴县| 大姚县| 高雄市| 乐东| 陇西县| 观塘区| 武邑县| 光泽县| 望都县| 保定市| 陇西县| 遵义市| 水城县| 平阴县| 花莲市| 会理县| 七台河市| 通州区| 广昌县| 常山县| 榕江县| 洱源县| 芮城县| 淳化县| 承德市| 临朐县| 正安县| 亚东县| 资讯 | 深水埗区|