如何遍历一个枚举?

来源:互联网 发布:省市县数据库 编辑:程序博客网 时间:2024/04/30 20:03
using  System; 
 
public  class  EnumTest  { 
       enum  Days  {  Saturday,  Sunday,  Monday,  Tuesday,  Wednesday,  Thursday,  Friday  }; 
 
       public  static  void  Main()  { 
 
               Type  weekdays  =  typeof(Days); 
 
               Console.WriteLine("The  days  of  the  week,  and  their  corresponding  values  in  the  Days  Enum  are:"); 
 
               foreach  (  string  s  in  Enum.GetNames(weekdays)  ) 
                       Console.WriteLine(  "{0,-11}=  {1}",  s,  Enum.Format(  weekdays,  Enum.Parse(weekdays,  s),  "d")); 
       } 
原创粉丝点击