枚举方面的问题 望高手指教
using System; using System.Collections.Generic; using System.Text; namespace 枚举方法 { public class ParseTest { [FlagsAttribute] enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 }; public static void Main() { Console.WriteLine("The entries of the Colors Enum are:"); foreach (string colorName in Enum.GetNames(typeof(Colors))) { Console.WriteLine("{0}={1}", colorName, Convert.ToInt32(Enum.Parse(typeof(Colors), colorName))); } Console.WriteLine(); Colors myOrange = (Colors)Enum.Parse(typeof(Colors), "Red, Yellow"); Console.WriteLine("The myOrange value {1} has the combined entries of {0}",myOrange, Convert.ToInt64(myOrange)); } } } 这个程序中: 这句 Console.WriteLine("{0}={1}", colorName, Convert.ToInt32(Enum.Parse(typeof(Colors), colorName))); 和这句: Console.WriteLine("The myOrange value {1} has the combined entries of {0}",myOrange, Convert.ToInt64(myOrange)); 的结果为什么会是前一个数字和符号一一对应 而后一个却是将两个数值相加呢? } Console.WriteLine(); Colors myOrange = (Colors)Enum.Parse(typeof(Colors), "Red, Yellow"); Console.WriteLine("The myOrange value {1} has the combined entries of {0}",myOrange, Convert.ToInt64(myOrange)); } } } 这个程序中 | ||