switch case c# new 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 set value
int x = SwitchExpressionUsingGuardClause(y);
private int SwitchExpressionUsingGuardClause(int y)
{
switch (y)
{
case 0: return 10;
case 1: return 20;
default: return 5;
}
}