Switch With Enumeration


This program describe the switch control with enum. While using switch control one thing must keep in mind that C# does not support "fall through", means if you skip break keyword after any case  you get an error.


--------------------------------------------------------------------------------------------------
using System;

enum Games { Hockey,BasketBall,VolleyBall,Tennis }

class SwitchWithEnum_First
{
     public static void Main()
    {
         Games games = Games.Tennis;
 
         switch(games)
         {
                  case Games.Hockey :
                  Console.WriteLine("You Favourite Game is " + games);
                  break;
                 
                  case Games.BasketBall :
                  Console.WriteLine("You Favourite Game is " + games);
                  break;
                   
                 case Games.VolleyBall :
                 Console.WriteLine("You Favourite Game is " + games);
                 break;
               
                 case Games.Tennis :
                 Console.WriteLine("You Favourite Game is " + games);
                 break;
               
                 default :
                 Console.WriteLine("You are studious person");
                 break;
 
                }
         }
}

--------------------------------------------------------------------------------------------------
Switch With Enumeration Switch With Enumeration Reviewed by Baljeet Singh on 00:54 Rating: 5

No comments:

Powered by Blogger.