switch base case c# code example
Example 1: c# switch
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
scale = exponent switch
{
int n when (n >= 6 && n < 9) => "Million",
int n when (n >= 9 && n < 12) => "Billion",
int n when (n >= 12 && n < 15) => "Trillion",
int n when (n >= 15 && n < 18) => "Quadrillion",
int n when (n >= 18 && n < 21) => "Quintillion",
int n when (n >= 21 && n < 24) => "Sextillion",
int n when (n >= 24 && n < 27) => "Septillion",
int n when (n >= 27 && n < 30) => "Octillion",
30 => "Nonillion",
_ => "",
};