首页 > 编程语言 > 详细

c#&.NET3.0高级程序设计-02 Enum Demo

时间:2016-04-06 21:46:31      阅读:254      评论:0      收藏:0      [点我收藏+]
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

原文:http://www.cnblogs.com/pyzhu/p/5361103.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!