C# switch example

In this C# program, we will learn how to implement a switch case in C#. We will use a switch statement to display the name of the day based on the input entered by the user.

C# switch example Code:

private static void Main(string[] args)
        {
            Console.Write("Enter a number between 1-7 : ");
            int input = int.Parse(Console.ReadLine());

            switch (input)
            {
                case 1:
                    Console.Write("Day of the week is Monday.");
                    break;
                case 2:
                    Console.Write("Day of the week is Tuesday.");
                    break;
                case 3:
                    Console.Write("Day of the week is Wednesday.");
                    break;
                case 4:
                    Console.Write("Day of the week is Thursday.");
                    break;
                case 5:
                    Console.Write("Day of the week is Friday.");
                    break;
                case 6:
                    Console.Write("Day of the week is Saturday.");
                    break;
                case 7:
                    Console.Write("Day of the week is Sunday.");
                    break;
                default:
                    Console.Write("Invalid Number Entered.");
                    break;
            }

            Console.ReadLine();
        }

C# switch example Output:

CSharp-switch-example

 
Best quality Asp .Net Ajax Control Toolkit tutorials.

Give your valuable comments.

Name
Email
Comment
6 + 3 =
 

About Us | Terms of Use | Privacy Policy | Disclaimer | Contact Us Copyright © 2012-2024 CodingFusion
50+ C# Programs for beginners to practice