switch expression c#
var switchValue = 3;
var resultText = switchValue switch
{
1 or 2 or 3 => "one, two, or three",
4 => "four",
5 => "five",
_ => "unknown",
};
switch expression c#
var switchValue = 3;
var resultText = switchValue switch
{
1 or 2 or 3 => "one, two, or three",
4 => "four",
5 => "five",
_ => "unknown",
};
C# Switch and case
int number = 2;
switch(number)
{
case 1:
Console.WriteLine("Number is 1");
break;
case 2:
Console.WriteLine("Number is 2");
break;
}
how to study switch in c#
Console.Write("Input a number between 1 to 5 : ");
int num=Convert.ToInt32(Console.ReadLine());
switch(num){
case 1:
Console.Write("One");
break;
case 2:
Console.Write("Two");
break;
case 3:
Console.Write("Three");
break;
case 4:
Console.Write("Four");
break;
case 5:
Console.Write("Five");
break;
default:
Console.Write("default");
break;
}
//Wait before closing.
Console.ReadKey();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us