Answers for "c# switch"

C#
17

c# switch

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 January-16-2020
14

c# switch

string commandName = "start";

switch (commandName)
{
    case "start":
        Console.WriteLine("Starting service...");
        StartService();
        break;
    case "stop":
        Console.WriteLine("Stopping service...");
        StopService();
        break;
    default:
        Console.WriteLine(String.Format("Unknown command: {0}", commandName));
        break;
}
Posted by: Guest on June-09-2020
2

c# switch

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 December-06-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
5

c# switch

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

C# switch

switch(expression) 
{
  case x:
    // code block
    break;
  case y:
    // code block
    break;
  default:
    // code block
    break;
}
Posted by: Guest on November-26-2020
1

C# Switch

int var = 3;

switch (var)
{
  case 1:
    Console.WriteLine("Ahoy!");
	break;
  case 2:
    Console.WriteLine("Hi!");
    break;
  case 3:
    Console.WriteLine("HELLO!");
    break;
}

//Output: HELLO!
Posted by: Guest on November-23-2020
1

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

c# switch

scale = exponent switch
        {
            int n when (n >= 6 && n < 9) => "Million",
            int n when (n >= 9 && n < 12) => "Billion",
            int n when (n >= 12 && n < 15) => "Trillion",
            int n when (n >= 15 && n < 18) => "Quadrillion",
            int n when (n >= 18 && n < 21) => "Quintillion",
            int n when (n >= 21 && n < 24) => "Sextillion",
            int n when (n >= 24 && n < 27) => "Septillion",
            int n when (n >= 27 && n < 30) => "Octillion",
            30 => "Nonillion",
            _ => "",
        };
Posted by: Guest on April-09-2021
0

c# switch

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 February-11-2021

C# Answers by Framework

Browse Popular Code Answers by Language