c# swtitch case when 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;
}
}
}
Example 2: c# switch case greater than
int mark = 50;
switch (mark)
{
case int n when n >= 80:
Console.WriteLine("Grade is A");
break;
case int n when n >= 60:
Console.WriteLine("Grade is B");
break;
case int n when n >= 40:
Console.WriteLine("Grade is C");
break;
default:
Console.WriteLine("Grade is D");
break;
}