C#中列舉型別的使用

iamzxf發表於2015-04-21


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace enumDemo
{
    enum Days : int 
    {
        Sun, Mon, Tue, Wed, Thu, Fri, Sat
    }

    class Program
    {
        static void Main(string[] args)
        {
            Days day = Days.Sun;

            if (Days.Sun == 0)
                Console.WriteLine("可以比較");

            Console.WriteLine(day+3);

            for (day = Days.Sun; day <= Days.Sat; day++)
                Console.Write("{0,5}",day);

            Console.WriteLine();

            foreach(string s in Enum.GetNames(typeof(Days)))
                Console.Write("{0,5}", s);

            
            Console.WriteLine();
            Console.WriteLine(Enum.GetName(typeof(Days), 4));

            Console.ReadLine();
        }
    }
}



相關文章