C#列挙とswitchの使い方


using System;  
  
namespace Csharp  
{  
    class Program  
    {  
        //   
        public enum TimeOfDay  
        {  
            Morning=0,  
            Afternoon=1,  
            Evening=2  
        }  
  
        static void Main()  
        {  
            WriteGreeting(TimeOfDay.Morning);  
            WriteGreeting(TimeOfDay.Afternoon);  
            WriteGreeting(TimeOfDay.Evening);  
            Console.ReadLine();  
        }  
        static void WriteGreeting(TimeOfDay timeofday)  
        {  
            //switch   
            switch (timeofday)  
            {  
                case TimeOfDay.Morning:  
                    Console.WriteLine("Good morning!");  
                    break;  
                case TimeOfDay.Afternoon:  
                    Console.WriteLine("Good afternoon!");  
                    break;  
                case TimeOfDay.Evening:  
                    Console.WriteLine("Good evening!");  
                    break;  
                default:  
                    Console.WriteLine("Hello!");  
                    break;  
            }  
        }  
    }  
}