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. case useing range

case useing range

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 3 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.
  • A Offline
    A Offline
    amatbrewer
    wrote on last edited by
    #1

    Is it possible to assign a range to a case statement? If not, is there a different way to accomplish the same thing? For example: Switch (int x) { Case 0 to 5: Case 6 to 10: Case 11 to 15: Default: } Thanks!

    David Wilkes

    D K 2 Replies Last reply
    0
    • A amatbrewer

      Is it possible to assign a range to a case statement? If not, is there a different way to accomplish the same thing? For example: Switch (int x) { Case 0 to 5: Case 6 to 10: Case 11 to 15: Default: } Thanks!

      David Wilkes

      D Offline
      D Offline
      Dan Neely
      wrote on last edited by
      #2

      Unfortunately not. your only option is an if/else structure. if ((0 <= x) && (x <=5)) else ...

      -- Rules of thumb should not be taken for the whole hand.

      1 Reply Last reply
      0
      • A amatbrewer

        Is it possible to assign a range to a case statement? If not, is there a different way to accomplish the same thing? For example: Switch (int x) { Case 0 to 5: Case 6 to 10: Case 11 to 15: Default: } Thanks!

        David Wilkes

        K Offline
        K Offline
        Karthik Kalyanasundaram
        wrote on last edited by
        #3

        You can accomplish the same using this, Switch (int x) { Case 0: Case 1: Case 2: Case 3: Case 4: Case 5: //Do processing here. break; ... Default: }

        A 1 Reply Last reply
        0
        • K Karthik Kalyanasundaram

          You can accomplish the same using this, Switch (int x) { Case 0: Case 1: Case 2: Case 3: Case 4: Case 5: //Do processing here. break; ... Default: }

          A Offline
          A Offline
          amatbrewer
          wrote on last edited by
          #4

          Thats good thinking, I should have remembered that since I have used similar structures in the past. However, I only see that as workable within a limited range. I am looking at ranges like 0-512, 513-1024, 1025-2048... Sadly there is not a consistent step size, or I would simply divide the value by the step size. Thanks for the response! This is a helpful & responsive group!

          David Wilkes

          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