C#.NET中的枚举类型(关键字enum)
/*
* Created by SharpDevelop.
* User: noo
* Date: 2009-8-16
* Time: 21:03
*
* 枚举类型
*/
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,
}
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);
enumC p=enumC.top ;
enumC q=enumC.buttom ;
byte r=(byte)enumC.buttom ;
Console.WriteLine (p);
Console.WriteLine (q);
Console.WriteLine (r);
}
}
* Created by SharpDevelop.
* User: noo
* Date: 2009-8-16
* Time: 21:03
*
* 枚举类型
*/
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,
}
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);
enumC p=enumC.top ;
enumC q=enumC.buttom ;
byte r=(byte)enumC.buttom ;
Console.WriteLine (p);
Console.WriteLine (q);
Console.WriteLine (r);
}
}
运行结果