how to add an or statement to switch case in c# code example
Example 1: c# switch case with or condition
int i = 5;
switch (i)
{
case(1):
case(2):
Console.WriteLine(i);
break;
default:
break;
}
Example 2: c# switch case
public class Example
{
// Button click event
public void Click(object sender, RoutedEventArgs e)
{
if (sender is Button handler)
{
switch (handler.Tag.ToString())
{
case string tag when tag.StartsWith("Example"):
// your code
break;
default:
break;
}
}
}
}