C#枚举类型实例演示

 
 
  1. using System ;  
  2. enum enumA:int 
  3. {  
  4.     east,//0  
  5.     south,//1  
  6.     west,//2  
  7.     north,//3  
  8. }  
  9. enum enumB//默认是int型的  
  10. {  
  11.     left,//0  
  12.     right,//1  
  13. }  
  14. enum enumC:byte 
  15. {  
  16.     top,  
  17.     buttom,  
  18. }  //C#枚举类型
  19. class Test  
  20. {  
  21.     static void Main()  
  22.     {  
  23.         enumA a=enumA.east;  
  24.         enumA b=enumA.south;  
  25.         enumA c=enumA.west;  
  26.         enumA d=enumA.north;  
  27.         Console.WriteLine (a);  
  28.         Console.WriteLine (b);  
  29.         Console.WriteLine (c);  
  30.         Console.WriteLine (d);  
  31.           
  32.         int aa=(int)enumA.east;  
  33.         int bb=(int)enumA.south;  
  34.         int cc=(int)enumA.west;  
  35.         int dd=(int)enumA.north;  
  36.         Console.WriteLine (aa);  
  37.         Console.WriteLine (bb);  
  38.         Console.WriteLine (cc);  
  39.         Console.WriteLine (dd);  
  40.           
  41.         enumB x=enumB.left ;  
  42.         enumB y=enumB.right ;  
  43.         int z=(int)enumB.left;  
  44.         Console.WriteLine (x);  
  45.         Console.WriteLine (y);  
  46.         Console.WriteLine (z);  
  47.          //C#枚举类型 
  48.         enumC p=enumC.top ;  
  49.         enumC q=enumC.buttom ;  
  50.         byte r=(byte)enumC.buttom ;  
  51.         Console.WriteLine (p);  
  52.         Console.WriteLine (q);  
  53.         Console.WriteLine (r);  
  54.     }  

C#枚举类型实例运行结果

C#枚举类型实例运行结果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值