c# switch cases are as many as list.count code example
Example 1: c# switch
string commandName = "start";
switch (commandName)
{
case "start":
Console.WriteLine("Starting service...");
StartService();
break;
case "stop":
Console.WriteLine("Stopping service...");
StopService();
break;
default:
Console.WriteLine(String.Format("Unknown command: {0}", commandName));
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;
}