locked
Text in switch RRS feed

  • Question

  • User1531104412 posted
    Hi. How can i enter a string in switch(?)?
    Wednesday, July 22, 2020 1:38 PM

All replies

  • User475983607 posted

    Hi. How can i enter a string in switch(?)?

    string caseSwitch = "1";
    
    switch (caseSwitch)
    {
        case "1":
            Console.WriteLine("Case 1");
            break;
        case "2":
            Console.WriteLine("Case 2");
            break;
        default:
            Console.WriteLine("Default case");
            break;
    }

    See the C# programming guide.

    https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/switch

    Wednesday, July 22, 2020 1:46 PM
  • User-857013053 posted

    using System;

    class Abc {

    public static void main () {

    string str = "one";

    switch(str) {

    case "one":

          console.WriteLine("It is 1");

          break;

    case "two":

          console.WriteLine("It is 2");

         break;

    default:

         console.WriteLine("Nothng");

          break;

    }

    }

    }

    Output:

    It is 1

    Friday, August 14, 2020 5:47 AM
  • User-1205502892 posted

    Thanks for the answer. It helped

    Flipaclip

    Friday, February 19, 2021 2:58 AM