• Home
  • Switch Conditional Statement

Switch Conditional Statement

Agenda

Switch Conditional Statement in C#

Syntax:

case value:

// code block

break;

case value:

// code block

break;.

.

.

default:

// code block

break;

}

Switch Statement Example with char Data Type

char grade = ‘A’;

switch (grade)

{

case ‘A’:

Console.WriteLine(“Excellent”);

break;

case ‘B’:

Console.WriteLine(“Very Good”);

break;

case ‘C’:

Console.WriteLine(“Good”);

break;

case ‘D’:

Console.WriteLine(“Average”);

break;

default:

Console.WriteLine(“Invalid Grade”);

break;

}

 
int studentclass = 2;


switch (studentclass)
{
case 1:
Console.WriteLine("Student belong to Primary standard I");
break;
case 2:
Console.WriteLine("Student belong to Primary standard II");
break;


case 3:
Console.WriteLine("Student belong to Primary standard III");
break;


case 4:
Console.WriteLine("Student belong to Primary standard IV");
break;


default:
Console.WriteLine("Student does not belong to Primary Standard");
break;


}

char grade = 'A';


switch (grade)
{
case 'A':
Console.WriteLine("Excellent");
break;
case 'B':
Console.WriteLine("Very Good");
break;
case 'C':
Console.WriteLine("Good");
break;
case 'D':
Console.WriteLine("Average");
break;
default:
Console.WriteLine("Invalid Grade");
break;
}