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的类型:
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