Switch Statement in C#

aaaaaaaaaaaaaaaaa

General form of Switch Statement


switch(integer expression)
{
    case constant 1:
        do this;
    case constant 2:
        do this;
    case constant 3:
        do this;
    default:
        do this;
}

Switch Statement Finding Integers

Program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            int i;
            Console.WriteLine("enter number from 1 to 4");
            i = Int32.Parse(Console.ReadLine());
            switch (i) //when U enter a number the number assigning to 'i'
            {  //and when we write like 'switch (i)' mean's it searching 'i' value.
                case 1: //if case 1, means 'i' have 1 value then print
                    Console.WriteLine("U entered 1"); //this line.
                    break; //'break;' means break the operation here if 'i' have 1.
                case 2: //if 'i' have not 1 value then cheak this, if not this
                    Console.WriteLine("U entered 2"); //then check another.
                    break;
                case 3:
                    Console.WriteLine("U entered 3");
                    break;
                case 4:
                    Console.WriteLine("U entered 4");
                    break; //break is must,without it not working.
            }
            Console.ReadLine();
        }
    }
}
Output
Hello World!

Switch Statement Finding Alphabets

Program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            char i; //U also write 'char' OR 'Char', its used for characters.
            Console.WriteLine("enter characters A,a,B,b and C");
            i = Char.Parse(Console.ReadLine());//'Char' not working directly
            switch (i)     //U must convert means use 'Char.Parse' for assigning value
            {             //to Char like 'i' in running time.
                case 'A': //if U enter capital and small font 'A or a' then it
				case 'a': //printing 'U entered A/a'.
                    Console.WriteLine("U entered A/a");
                    break;
                case 'B':
                    Console.WriteLine("U entered B");
                    break;
                case 'b':
                    Console.WriteLine("U entered small font b");
                    break;
				case 'C':
                    Console.WriteLine("U entered C");
                    break;
            }
            Console.ReadLine();
        }
    }
}
Output
Hello World!

Switch Statement Finding Name like Password
Program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string na; //U also use 'String' OR 'string' it is Ur choice.
            Console.WriteLine("Please Enter Ur name");
             na = Console.ReadLine(); //it working directly bcz I used string.
            switch (na)
            {
                case "Bilal": //for string U must use double quotes '"' like here.
                    Console.WriteLine("OK Bilal!");
                    break;
                case "Khan":
                    Console.WriteLine("OK Khan!");
                    break;
                case "Afridi":
                    Console.WriteLine("OK Afridi");
                    break;
            }
            Console.ReadKey();
        }
    }
}
Output
Hello
World!