日期:2014-05-18 浏览次数:20524 次
using System; enum Color:byte{ Red, Green, Blue, Orange } class Program { static void Main() { string[] ss = Enum.GetNames (typeof(Color)); byte [] bb = (byte[])Enum.GetValues(typeof(Color)); for (int i = 0; i < ss.Length; i++) { Console.WriteLine("{0,10}: {1}", ss[i], bb[i]); } } } /* 程序输出: Red: 0 Green: 1 Blue: 2 Orange: 3 */
------解决方案--------------------
foreach (byte i in (byte[])Enum.GetValues(typeof(Color))) { Console.WriteLine("{0,10}: {1}", (Color)i, i); }