黑马程序员技术交流社区

标题: .net中泛型集合的小结 [打印本页]

作者: 李洋    时间: 2013-10-21 10:00
标题: .net中泛型集合的小结
本帖最后由 李洋 于 2013-10-21 10:01 编辑

C#枚举类型使用的时候需要掌握的有哪些方面呢?首先我们来看看一个例子:

public enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };    The entries of the Colors Enum are:  Red  Green  Blue  Yellow C#枚举类型使用的一点总结之根据name获得Enum的类型:

Colors mycolor = (Colors)Enum.Parse(  typeof(Colors),"red",true);  (int)mycolor1=1  mycolor1.GetTypeCode=Int32 C#枚举类型使用的一点总结之根据value获得Enum的类型:

Colors mycolor = (Colors)Enum.Parse(  typeof(Colors),"1",true);  mycolor2.ToString()=Red  mycolor2.GetTypeCode=Int32 C#枚举类型使用的一点总结之遍历枚举内容

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  





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2