Switch Statement in C#
The switch statement is like a set of if statements which allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.
Program
using System;
namespace switch_statement
{
class Program
{
/* local variable definition */
static void Main(string[] args)
{
char number = 'b';
switch (number)
{
case 'a':
Console.WriteLine("Very Good!");
break;
case 'b':
case 'c':
Console.WriteLine("Good");
break;
}
Console.WriteLine("You are in {0}", number+" level.");
Console.ReadLine();
}
}
}
Output- Good
You are in b level
The switch statement is like a set of if statements which allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.
Program
using System;
namespace switch_statement
{
class Program
{
/* local variable definition */
static void Main(string[] args)
{
char number = 'b';
switch (number)
{
case 'a':
Console.WriteLine("Very Good!");
break;
case 'b':
case 'c':
Console.WriteLine("Good");
break;
}
Console.WriteLine("You are in {0}", number+" level.");
Console.ReadLine();
}
}
}
Output- Good
You are in b level