Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. switch statement

switch statement

Scheduled Pinned Locked Moved C#
csharpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    blackjack2150
    wrote on last edited by
    #1

    :wtf: Doesn't the switch statement in C# support multiple options inside the case clause??? I'm sorry if I missed it.

    B M 2 Replies Last reply
    0
    • B blackjack2150

      :wtf: Doesn't the switch statement in C# support multiple options inside the case clause??? I'm sorry if I missed it.

      B Offline
      B Offline
      Brady Kelly
      wrote on last edited by
      #2

      No, but you can use empty case labels to achieve this. Example switch (x) { case 1: case 2: DoOneAndTwo; break; }

      1 Reply Last reply
      0
      • B blackjack2150

        :wtf: Doesn't the switch statement in C# support multiple options inside the case clause??? I'm sorry if I missed it.

        M Offline
        M Offline
        Muammar
        wrote on last edited by
        #3

        blackjack2150 wrote:

        multiple options inside the case clause???

        :confused: What do you mean?? Another switch case statement??


        Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)

        B 1 Reply Last reply
        0
        • M Muammar

          blackjack2150 wrote:

          multiple options inside the case clause???

          :confused: What do you mean?? Another switch case statement??


          Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)

          B Offline
          B Offline
          blackjack2150
          wrote on last edited by
          #4

          I mean something like this: switch(DayOfWeek) { case "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" : work = true; case "Saturday", "Sunday": party = true; } VB .NET for example has it and that's quite sad for me, as I've preferred C# over VB.

          W 1 Reply Last reply
          0
          • B blackjack2150

            I mean something like this: switch(DayOfWeek) { case "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" : work = true; case "Saturday", "Sunday": party = true; } VB .NET for example has it and that's quite sad for me, as I've preferred C# over VB.

            W Offline
            W Offline
            woudwijk
            wrote on last edited by
            #5

            switch (DayOfWeek) { case DayOfWeek.Monday: case DayOfWeek.Tuesday: case DayOfWeek.Wednesday: case DayOfWeek.Thursday: case DayOfWeek.Friday: work = true; break; case DayOfWeek.Saturday: case DayOfWeek.Sunday: party = true; break; } well, it works for me... think you may be doing something wrong

            My second computer is your linux box.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups