Switch with enum : Enum switch : Data Type C# Examples


C# Examples » Data Type » Enum switch »

 

Switch with enum









    
using  System;
public  enum  TimeOfDay  {
        Morning  =  0,
        Afternoon  =  1,
        Evening  =  2
}

class  EnumExample  {
        public  static  void  Main()  {
                WriteGreeting(TimeOfDay.Morning);

        }

        static  void  WriteGreeting(TimeOfDay  timeOfDay)  {
                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;
                }
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Type
» Enum switch