how to use a switch case in a while in c# 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: switch c#
switch(expression)
{
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
break;
}