路漫漫其修远兮!
专注于Windows API、.NET、虚拟化、企业信息化及网络技术。
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();
    }   

}

posted on 2016-04-06 21:00  艺歆  阅读(139)  评论(0)    收藏  举报