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 9309333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:50:27+00:00 2026-06-19T00:50:27+00:00

I have read in various places that switch statements with string cases can potentially

  • 0

I have read in various places that switch statements with string cases can potentially be optimized (by the compiler or the JIT) into hash tables to improve performance. Hash tables with non-perfect hashing functions obviously do not guarantee item order, and so I was wondering:

  1. Can the C# compiler or the JIT perform an optimization that converts a switch statement to a hash table to provide constant-time performance?
  2. Do switch statements in C# guarantee that the case‘s are checked in order, from top to bottom?
  • 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-06-19T00:50:28+00:00Added an answer on June 19, 2026 at 12:50 am

    No, there is no any guarantee that the order will be maintained, as this is a purely compiler implementation detail, so even if it’s would be true now, for .net 5.1 (say), may be wrong.

    switch/case construct is made for identifying unique option(s) between different available ones. So, the order does not matter, if not from performance point of view, but even there, it’s basically irrelevant, and if not, it could not be predicted for the reasons described above.

    So just not pay attention to this, and look on other parts of your program, if you’re looking for some performance bottlenecks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read in various places that having variables with global scope, i.e. a
I have read a file into a String. The file contains various names, one
I've read in various places that one important requirement in DDD is to have
Basically I have a script that updates an xml document in various places... However,
I'm building a site using mongodb and django-nonrel. I've read in various places that
I have read various posts in stackoverflow and I am trying to figure out
I have read various articles about passing variables around using RMI. Some of them
I've read through the various posts on SO about this, but have still not
I have read various posts here at StackOverflow regarding the execution of FFT on
I've read in different places that this is possible. I do not need to

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.