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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:42:12+00:00 2026-06-08T19:42:12+00:00

I have a SELECT/SWITCH statement that has continued to grow… I THINK I should

  • 0

I have a SELECT/SWITCH statement that has continued to grow… I THINK I should be about done.
However, there are currently 19 options… is there something that would be better than this?

Coding in C#

IE:

switch (Request["typeOfRequest"].ToString())
        {
            case "comboFills":
                Response.ContentType = "text";
                Response.Write(getVizData());
                break;
            case "linkFormField":
                Response.ContentType = "text";
                Response.Write(getVizRuleFields());
                break;
            case "getDispositions":
  • 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-08T19:42:14+00:00Added an answer on June 8, 2026 at 7:42 pm

    Switch statements can be way larger than that… However, eventually you may run into efficiency concerns. I don’t think that 19 cases is a problem. I’ve had much larger statements. Usually a switch statement is not a processing bottleneck, so it’s the last thing you optimize.

    Each case translates onto the CPU as a test and a jump, so think of how many operations your worst case would be and decide whether it’s worth fussing over, and how many operations you would actually save (both worst case and average).

    Saying that, there’s a couple of obvious options. If you have numeric types and they are evenly distributed, you can split your switch statement into multiple switches….

    if value < 50
      switch
        ...
      end
    else if value < 100
      switch
        ...
      end
    else
      ...
    end
    

    This is of course trickier to maintain, and may rely upon knowledge of constant values that makes your code ugly. It’s really just a grungey search tree…

    Another way is to put all your cases into functions, and build a tree or hash table that maps each value to a function handler. That way you can always rely on O(logN) search times (or better, in the case of hash tables). I repeat: don’t do this unless you have a very good reason to.

    Hope that helps give you some insight. Apologies for not being language-specific. You didn’t mention a language, but I’m assuming it’s something like BASIC.

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

Sidebar

Related Questions

I have a switch statement in a Crystal Report that looks like this: stringvar
I have an item model that has a name and a price (int). How
I have a UDF that queries data out of a table. The table, however,
I am writing some code in VB.NET that uses a switch statement but in
I need to declare the query variable outside the switch statement that way I
I have a complicated SELECT query that filters on a time range, and I
The following switch statement is not catching a cookie that does not exist. switch
I have the following switch statement in JavaScript : switch(scrollable.direction){ case top : break;
Below is my category.php that uses a switch statement to either show subcategories or
I have some html that creates a dropdown list. The list has text values

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.