C#.NET中的枚举类型(关键字enum)
2009-08-16 21:30
543 查看
/*
* 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);
}
}
运行结果
相关文章推荐
- C#.NET验证码智能识别学习笔记---02-C#.Net中Using关键字的用法
- C#(ASP.NET)正则表达式 过滤危险字符函数代码 防SQL注入 很全面的SQL关键字过滤
- C# 枚举类型enum与字符间的换换
- Net学习难点讨论系列2 – 细说C#中new关键字与多态
- .NET(c#)new关键字的三种用法
- C#.net 关键字之virtual老司机教学
- C#.Net 中枚举类型的数据在PropertyGrid控件中的显示中文描述
- C#.NET中命名空间的运用(关键字namespace)
- C#.NET中的base关键字在派生类里的应用
- NET面试题:C#中的lock关键字有何作用
- asp.net(c#) static关键字用法小结+示例代码
- .NET(c#)new关键字的三种用法
- .NET(c#)new关键字的三种用法
- .NET(c#)new关键字的三种用法
- c#.net环境函数的参数数组的用法(关键字params)
- c#.net中通过关键字检索指定文件夹中的word文档
- .net(c#)中的new关键字
- asp.net(c#) static关键字用法小结
- C#语法小知识(三)枚举类型enum
- <NET CLR via c# 第4版>笔记 第15章 枚举类型和位标志