Answers for "c# switch case string"

C#
6

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
Posted by: Guest on January-08-2021
5

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
Posted by: Guest on May-29-2020
0

multi case in c#

switch (value)
{
   case var s when new[] { 1,2,3 }.Contains(s):
      // Do something
      break;
   case var s when new[] { 4,5,6 }.Contains(s):
      // Do something
      break;
   default:
      // Do the default
      break;
}
Posted by: Guest on October-30-2020
0

C# switch stmt

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
 class Program
 {
  static void Main(string[] args) 
  {
   Int32 value=11;
   switch(value) 
   {
     case 1: Console.WriteLine("Value is 1");	
     break;
     case 2: Console.WriteLine("Value is 2");
     break;
     default: Console.WriteLine("value is different");
     break;
   }
  }
 }
}
Posted by: Guest on November-14-2021

C# Answers by Framework

Browse Popular Code Answers by Language