Answers for "c# switch example"

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 statement

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
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 example

switch (iGender)
            {
                case 1:
                    LabelOne.Text = "Male";
                    break;

                case 2:
                    LabelOne.Text = "Female";
                    break;
Posted by: Guest on February-03-2021

C# Answers by Framework

Browse Popular Code Answers by Language