C#枚举类型实例演示
- /*
- * Created by SharpDevelop.
- * User: noo
- * Date: 2009-8-16
- * Time: 21:03
- *
- * C#枚举类型
- */
- using System ;
- enum enumA:int
- {
- east,//0
- south,//1
- west,//2
- north,//3
- }
- enum enumB//默认是int型的
- {
- left,//0
- right,//1
- }
- enum enumC:byte
- {
- top,
- buttom,
- } //C#枚举类型
- class Test
- {
- static void Main()
- {
- enumA a=enumA.east;
- enumA b=enumA.south;
- enumA c=enumA.west;
- enumA d=enumA.north;
- Console.WriteLine (a);
- Console.WriteLine (b);
- Console.WriteLine (c);
- Console.WriteLine (d);
- int aa=(int)enumA.east;
- int bb=(int)enumA.south;
- int cc=(int)enumA.west;
- int dd=(int)enumA.north;
- Console.WriteLine (aa);
- Console.WriteLine (bb);
- Console.WriteLine (cc);
- Console.WriteLine (dd);
- enumB x=enumB.left ;
- enumB y=enumB.right ;
- int z=(int)enumB.left;
- Console.WriteLine (x);
- Console.WriteLine (y);
- Console.WriteLine (z);
- //C#枚举类型
- enumC p=enumC.top ;
- enumC q=enumC.buttom ;
- byte r=(byte)enumC.buttom ;
- Console.WriteLine (p);
- Console.WriteLine (q);
- Console.WriteLine (r);
- }
- }
C#枚举类型实例运行结果
C#枚举类型实例演示的基本情况就向你介绍到这里,希望对你了解和学习C#枚举类型有所帮助。
【编辑推荐】