Multiple cases in switch statement in C#
To do multiple cases in switch statement in C# you directly add cases within same line.Syntax:
case condition1: case condition2: case conctions3: ...
Example
using System;
public class Program
{
public static void Main()
{
int number = 6;
switch (number)
{
case 1: case 2: case 3: // Three conditions here for: 1, 2 & 3
Console.WriteLine("Number is lower than 4!");
break;
case 4: case 5: case 6: // Three conditions here for: 4, 5 & 6
Console.WriteLine("Number is lower than 7, and higher than 3!");
break;
default:
Console.WriteLine("Number is higher than 6!");
break;
}
}
}
Output
Number is lower than 7, and higher than 3!