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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:23:55+00:00 2026-05-31T08:23:55+00:00

I am trying to convert a JavaScript switch to a C# one. I am

  • 0

I am trying to convert a JavaScript switch to a C# one.

I am getting error Error 3 Cannot implicitly convert type 'bool' to 'int'

        switch (numero)
        {
            case (numero > -1 && numero < 16):
                rtn = list1[numero] + " " + str2;
                if (primerDigito != 1)
                {
                    rtn += "s";
                }
                break;
            case (numero > 15 && numero < 30):
                if (numero != 20)
                {
                    rtn = list2[primerDigito] + list1[segundoDigito];
                }
                else
                {
                    rtn = "veinte";
                }
                rtn += " " + str2 + "s";
                break;
            case (numero > 29 && numero < 100):
                rtn = list2[primerDigito] + "nta";
                if (segundoDigito != 0)
                {
                    rtn += " y " + list1[segundoDigito];
                }
                rtn += " " + str2 + "s";
                break;
            case 100:
                rtn = "cien " + str2 + "s";
                break;
            default:
                rtn = "número invalido";
        }

Is there a work around for this?

Note: I really MUST use switch-case (and not if-elses)

  • 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-31T08:23:56+00:00Added an answer on May 31, 2026 at 8:23 am

    You cannot do this: a switch statement can only use single values, not ranges for the cases.

    You need an if/else tree instead. Something in the form of:

    if(numero > -1 && numero < 16) {
     rtn = list1[numero] + " " + str2;
     if (primerDigito != 1)
     {
      rtn += "s";
     }
    } else if(numero > 15 && numero < 30) {
     // logic in second block
    } else if...
    

    Note that if you’re absolutely, totally committed to using a switch, you would have to enumerate all of the cases (but this is such an egregious sin against software engineering that I can’t even believe I’m writing it out – do not do this, it’s just an example of how switch statements work):

    switch(numero)
    {
     case 0:
     case 1:
     case 2:
     case 3:
     case 4:
     case 5:
     case 6:
     case 7:
     case 8:
     case 9:
     case 10:
     case 11:
     case 12:
     case 13:
     case 14:
     case 15:
      rtn = list1[numero] + " " + str2;
      if (primerDigito != 1)
      {
       rtn += "s";
      }
      break;
     case 16:
     ...
     case 28:
     case 29:
      // second logic block
      break;
     ...
    }
    

    If I saw this in my codebase, though, I would be baffled and angry.

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

Sidebar

Related Questions

I'm trying to convert an if statement into a switch statement using javascript. This
I´m trying to convert that: <% var obj = Model.Div; %> <script type=text/javascript> var
I'm trying to convert the following jquery to javascript syntax, but being not familiar
I'm trying to convert date formats in javascript. I get a string from a
I am trying in javascript to convert an integer (which I know will be
Trying to convert this c code into MIPS and run it in SPIM. int
Trying to convert int arrays to string arrays in numpy In [66]: a=array([0,33,4444522]) In
Im trying to convert unixtime to date but the results im getting are wrong
I'm trying to convert a Javascript array in Java to a Java array. I'm
I'm trying to convert this Javascript code: self.userSerialEvent = function (join, value, tokens) {

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.