CSharp – Switch Statement

The switch statement is like a set of if statements. It’s a list of possibilities, with an action for each possibility, and an optional default action, in case nothing else evaluates to true.

switch case


using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            int caseSwitch = 1;
            switch (caseSwitch)
            {
                case 1:
                    Console.WriteLine("Case 1");
                    break;
                case 2:
                    Console.WriteLine("Case 2");
                    break;
                // if case 1 and case 2 are false:
                default:
                    Console.WriteLine("Default case");
                    break;
            }
        } // End Main()
    }
}

switch case – while

How to create a loop:

...
case 4:
    while (true)
        Console.WriteLine("Endless looping. . . .");
...