enum遍历http://topic.csdn.net/t/20030613/00/1909808.html

来源:互联网 发布:java 0x00 编辑:程序博客网 时间:2024/06/05 09:58
enum   enu   {   a=1,   b=2,   c=3,   d=4   };  
  private   void   button2_Click(object   sender,   System.EventArgs   e)   {  
  //foreach  
  foreach(string   s   in   Enum.GetNames(typeof(enu))){  
  MessageBox.Show(s);  
  }  
   
  foreach(int   s   in   Enum.GetValues(typeof(enu)))   {  
  MessageBox.Show(s.ToString());  
  }  
   
  //to   Array[]  
  string[]   en   =   Enum.GetNames(typeof(enu));  
  Array   ev   =   Enum.GetValues(typeof(enu));  
  }    
原创粉丝点击