switch case condition 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
int randomNumber = rnd.Next(1, 2);
switch (randomNumber)
{
case 1:
Console.WriteLine("randomNumber = 1!");
break;
case 2:
Console.WriteLine("randomNumber = 2!");
break;
default:
Console.WriteLine("something went wrong");
break;
}