http://www.aygfsteel.com/ebecket 返還網(wǎng)
          隨筆-140  評論-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 閱讀(686) 評論(0)  編輯  收藏 所屬分類: C#
          主站蜘蛛池模板: 海淀区| 德阳市| 玛多县| 阜南县| 福海县| 仁寿县| 呼和浩特市| 喀喇沁旗| 雅江县| 承德市| 中牟县| 东乡县| 佳木斯市| 前郭尔| 满洲里市| 东阳市| 长治市| 藁城市| 宁强县| 桃源县| 萍乡市| 威宁| 夏河县| 屏山县| 崇左市| 上杭县| 玉龙| 太和县| 安岳县| 广宗县| 婺源县| 贵阳市| 高台县| 胶州市| 怀集县| 米易县| 宜州市| 庆城县| 平凉市| 弥渡县| 长治县|