Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4611216
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:14:17+00:00 2026-05-22T01:14:17+00:00

I was reading an interesting article here and it made an interesting point about

  • 0

I was reading an interesting article here and it made an interesting point about the ‘case’ statement in vb.net vs the ‘switch’ statement in C#, which I’ve pasted below:

The following Visual Basic Select Case statement can’t be represented in C# with a single switch statement:

Dim Condition As Integer = 55
Select Case Condition
  Case 1, 3 To 5, 10, 12, 14, Is > 50
    'value 55 executes code here
  Case Else
    'values <1, 2, 6-9, 11, 13, 15-49
End Select

I’ve always found the switch statement in C#, with dropthrough and consequentrequirements for a break in each case, to be a bit unwieldy. Is there any reason they haven’t enhanced the switch command to allow these situations? When would dropthrough be useful anyway? Anyone know of any extensions of the construct to allow more flexibility?

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:14:18+00:00Added an answer on May 22, 2026 at 1:14 am

    In C# you can only use distinct values in cases. This makes it more limited, but on the other hand it makes it faster because it can be implemented using a hash lookup.

    The switch syntax has been made more restricted in C# than in C/C++. You can still do the same things, but a fall through is not made implicitly, you have to write a specific jump to the next case. The reason for this restriction is that it’s much more common to do fall through by mistake than intentionally.

    In C# you would need an if statement in the default case to handle the ranges:

    int condition = 55;
    switch (condition) {
      case 1:
      case 3:
      case 4:
      case 5:
      case 10:
      case 12:
      case 14:
        // values 1, 3-5, 10, 12, 14
        break;
      default:
        if (condition > 50) {
          // value 55 executes code here
        } else {
          // values <1, 2, 6-9, 11, 13, 15-49
        }
        break;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have been reading this interesting article which is increasing my every growing confusion
I'm reading a book about programming ASP.NET in C#. The book makes the following
I've been wondering about this for a while after reading through an interesting article
I was reading about floating-point representation and underflow/overflow and I ecnountered something interesting -
I've been reading this article about closures in which they say: all the plumbing
I was reading this article about ADO.NET Entity Framework and found it to be
C#.NET 4.0 I'm having an interesting problem here with reading a custom file archive
After reading an interesting article about unit testing behavior instead of state, I came
After carefully reading this KB article I noticed an interesting statement there. The article
Reading about the G.729 codec , I found this interesting tidbit about Comfort Noise

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.