C#遍历枚举(Enum)
1 public enum WeekDay 2 { 3 Sun=0, 4 Mon=1, 5 Tue=2, 6 Wed=3, 7 Thu=4, 8 Fri=5, 9 Sat=6, 10 } 11 static void Main(string[] args) 12 { 13 foreach (WeekDay day in Enum.GetValues(typeof(WeekDay))) 14 { 15 Console.WriteLine((int)day+":"+day); 16 } 17 Console.ReadKey(); 18 }
结果如下图: