Wednesday 27 July 2016

C Sharp Switch Case Tutorial

C # Switch Case Program

 class Program
    {
        static void Main(string[] args)
        {
            int i;
            Console.Write("Enter day of the week>> ");
            i=int.Parse(Console.ReadLine());
            switch(i)
            {
                case 1:

                    Console.WriteLine("Sun");
                    break;
                case 2:
                       Console.WriteLine("Mon");
                       break;
                case 3:
                        Console.WriteLine("Tue");
                        break;
                default :
                        Console.WriteLine("Invalid OPtion");
                        break;
            }
        }
    }

Remark :  Break is mandatory in C#.

No comments:

Post a Comment