should i use a switch statement c# code example
Example 1: c# switct case
using System;
public class Example
{
public static void Main()
{
int caseSwitch = 1;
switch (caseSwitch)
{
case 1:
Console.WriteLine("Case 1");
break;
case 2:
Console.WriteLine("Case 2");
break;
default:
Console.WriteLine("Default case");
break;
}
}
}
// The example displays the following output:
// Case 1
Example 2: switch c#
switch(expression)
{
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
break;
}