c#&.NET3.0高级程序设计-02 Enum Demo
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c#&.NET3.0高级程序设计-02 Enum Demo相关的知识,希望对你有一定的参考价值。
Enum 实例
using System;
using System.Collections.Generic;
public class MyClass
{
enum EmpType
{
Manager,Grunt,Contractor,VP
}
static void AskForBonus(EmpType e)
{
switch(e)
{
case EmpType.Contractor:
Console.WriteLine("You are a dog!");
break;
case EmpType.Grunt:
Console.WriteLine("You are my friend!");
break;
case EmpType.Manager:
Console.WriteLine("How are you?");
break;
case EmpType.VP:
Console.WriteLine("How old are you!");
break;
default:break;
}
}
public static void Main(string[] args)
{
Array obj = Enum.GetValues(typeof(EmpType));
Console.WriteLine("This enum has {0} members.",obj.Length);
foreach(EmpType e in obj)
{
Console.WriteLine("String name:{0},",e.ToString());
Console.WriteLine("int:{0},",Enum.Format(typeof(EmpType),e,"D"));
Console.WriteLine("hex:{0},",Enum.Format(typeof(EmpType),e,"x"));
}
Console.ReadKey();
}
}
以上是关于c#&.NET3.0高级程序设计-02 Enum Demo的主要内容,如果未能解决你的问题,请参考以下文章