switch statement with less then c# core code example

Example 1: 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

Example 2: c# switch

int randomNumber = rnd.Next(1, 2); //a int tat equals 1 or 2

      switch (randomNumber) //the number we check the value of
      {
          case 1:
              Console.WriteLine("randomNumber = 1!");
              break;
          case 2:
              Console.WriteLine("randomNumber = 2!");
              break;
          default:	//the deafult state happens when the other casas do not
              Console.WriteLine("something went wrong");
              break;
      }