if 1 case is satisfied then will nother switch case will execute c# code example
Example 1: c# switch case
using System;
namespace DecisionMaking
{
class Program
{
static void Main(string[] args)
{
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
Example 2: c# switch
using System;
namespace SwitchStatement
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please write a movie genre.");
string genre = Console.ReadLine();
switch (genre)
{
case "Drama":
Console.WriteLine("Citizen Kane");
break;
case "Comedy":
Console.WriteLine("Duck Soup");
break;
case "Adventure":
Console.WriteLine("King Kong");
break;
case "Horror":
Console.WriteLine("Psycho");
break;
case "Science Fiction":
Console.WriteLine("2001: A Space Odyssey");
break;
default:
Console.WriteLine("No movie found.");
break;
}
}
}
}