(论坛答疑点滴)遍历枚举

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"));  
       }  
}  
posted @ 2006-01-19 11:26 lovecherry 阅读(2091) 评论(5)  编辑 收藏 网摘 所属分类: 其他

  回复  引用    
#1楼2006-02-23 14:26 | doney[未注册用户]
不错阿

  回复  引用    
#2楼2007-02-25 00:18 | dong[未注册用户]
it is useful:) thanks
  回复  引用    
#3楼2007-05-20 18:16 | FrozenPine[未注册用户]
很有用,解决了我遍历并获取枚举类型长度的问题。谢谢
  回复  引用  查看    
#4楼2007-11-26 11:11 | 阿生      
这样可以更简洁一些:
foreach( object o in Enum.GetValues(weekdays))
Console.WriteLine("{0,-11}={1}", o,(int)o);




发表评论

昵称: [登录] [注册]

主页:

邮箱:(仅博主可见)

评论内容:

  登录  注册

[使用Ctrl+Enter键快速提交评论]

0 320151




相关文章:

相关链接: