A switch statement allows checking a variable/value with a list of values (cases) and executing the block associated with that case.
Syntax:
switch(variable/expression)
{
case <case_value1>:
statement(s);
break;
case <case_value2>:
break;
default:
break;
}
Note:
C# code to demonstrate example of switch statement
Here, we are asking for a day number from the user between the range of 0 to 6, and printing day name (example: 0 for Sunday, 1 for Monday and so on...).
Output
C# code to check input character is a VOWEL or CONSOTANT using switch statement
Here, we are asking for a character from the user – and checking 1) input character is an alphabet using if-else statement and if it is an alphabet – we are checking for vowels & consonants.
Output