c# switch statement
string command = "stop";
switch(command){
case "start" :
Console.WriteLine("started your alexa");
break;
case "stop":
Console.WriteLine("stopped your alexa");
break;
c# switch statement
string command = "stop";
switch(command){
case "start" :
Console.WriteLine("started your alexa");
break;
case "stop":
Console.WriteLine("stopped your alexa");
break;
c# switch case
using System;
namespace DecisionMaking
{
class Program
{
static void Main(string[] args)
{
/* local variable definition */
char grade = 'B';
switch (grade)
{
case 'A':
Console.WriteLine("Excellent!");
break;
case 'B':
case 'C':
Console.WriteLine("Well done");
break;
case 'D':
Console.WriteLine("You passed");
break;
case 'F':
Console.WriteLine("Better try again");
break;
default:
Console.WriteLine("Invalid grade");
break;
}
Console.WriteLine("Your grade is {0}", grade);
Console.ReadLine();
}
}
}
=======OUTPUT========
Well done
Your grade is B
c# select 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;
}
}
}
// The example displays the following output:
// Case 1
c# switch case
// Switch Statement VS Switch Expression
static void TrafficUsingSwitchStatement(string color)
{
string result;
switch (color)
{
case "Red":
result = "Stop!"; break;
case "Yellow":
result = "Slow down!"; break;
case "Green":
result = "Go!"; break;
default:
result = "Invalid input!"; break;
}
Console.WriteLine(result);
}
static void TrafficUsingSwitchExpression(string color)
{
string result = color switch
{
"Red" => "Stop!",
"Yellow" => "Slow down!",
"Green" => "Go!",
_ => "Invalid input!"
};
Console.WriteLine(result);
}
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;
}
}
}
}
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;
}
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