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();
}
}