Answers for "switch case default c#"

C#
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
1

c# switch

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;
}
Posted by: Guest on July-11-2021
0

c# switch

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;
}
Posted by: Guest on December-08-2020
2

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;
                }
            }
  }
}
Posted by: Guest on August-27-2020
1

how to use switch statement in c#

/* Switch Statements are a cleaner way to write if and else statements like this: */

var randomNum = Mathf.Random.Range(0, 5);

// ofcourse this way is so dumb but its just for explaining
if (randomNum == 0) print("The correct number is 0");
else if (randomNum == 1) print("The correct number is 1");
else if (randomNum == 2) print("The correct number is 2");
else if (randomNum == 3) print("The correct number is 3");
else if (randomNum == 4) print("The correct number is 4");
else if (randomNum == 5) print("The correct number is 5");

// Instead of writing if and else statements like this we can use switch statements like this:

switch(randomNum)
{
  case 0:
    print("correct number is 0");
    break; // we must include a break statement at the end of every case.
    
  case 1:
    print("correct number is 1");
    break;
    
  case 2:
    print("correct number is 2");
    break;
    
  case 3:
    print("correct number is 3");
    break;
    
  case 4:
    print("correct number is 4");
    break;
    
  case 5:
    print("correct number is 5");
    break;
}
Posted by: Guest on June-25-2021

C# Answers by Framework

Browse Popular Code Answers by Language