C#]Enum枚举类型使用总结
public enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };
The entries of the Colors Enum are:
Red
Green
Blue
Yellow
根据name获得Enum的类型:
Colors mycolor = (Colors)Enum.Parse(typeof(Colors),"red",true);
(int)mycolor1=1
mycolor1.GetTypeCode=Int32
根据value获得Enum的类型:
Colors mycolor = (Colors)Enum.Parse(typeof(Colors),"1",true);
mycolor2.ToString()=Red
mycolor2.GetTypeCode=Int32
遍历枚举内容
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 阅读(679)
评论(0) 编辑 收藏 所属分类:
C#