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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:04:45+00:00 2026-05-29T05:04:45+00:00

I’m not looking for any specific code examples, but could someone explain why I

  • 0

I’m not looking for any specific code examples, but could someone explain why I can’t get the ‘-1’ to function at the end of this switch statement? It keeps saying that there are “too many literals” for type char. (something close to that). Would I have to convert this to another type?

Thanks for any help, and please, just explain without giving code. I would love to learn this by hands on experiance 😀

Convert 7 char passed from ProcessInput() by reference to upper case
Use switch statement to translate char into their corresponding digits (case statement for each digit and each valid uppercase letter)
**TROUBLES WITH THIS PART***Write default case that returns error code (-1) for invalid letters
If no invalide letters, return 0

    static void ToDigit(ref char digit)
    {

        digit = Char.ToUpper(digit);
        char result;

        switch (digit)
        {
            case '0':  result = '0';
                break;

            case '1': result = '1';
                break;

            case '2':
            case 'A':
            case 'B':
            case 'C': result = '2';
                break;

            case '3':
            case 'D':
            case 'E':
            case 'F': result = '3';
                break;

            case '4':
            case 'G':
            case 'H':
            case 'I': result = '4';
                break;

            case '5':
            case 'J':
            case 'K':
            case 'L': result = '5';
                break;

            case '6':
            case 'M':
            case 'N':
            case 'O': result = '6';
                break;

            case '7':
            case 'P':
            case 'Q':
            case 'R':
            case 'S': result = '7';
                break;

            case '8':
            case 'T':
            case 'U':
            case 'V': result = '8';
                break;

            case '9':
            case 'W':
            case 'X':
            case 'Y':
            case 'Z': result = '9';
                break;
                //Says I can't enter -1 as char "too many characters in character literal
            default: result = 'e';
                break;
        }
        digit = result;
    }
  • 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-29T05:04:46+00:00Added an answer on May 29, 2026 at 5:04 am

    A char is, as the name implies, a single character. A group of characters all “strung together” is called a string in C#.

    If you want the integer value -1 as a char then you can do that by saying unchecked((char)(-1)) (*) but you should be aware that this is a very bad idea. I assume that this is your assignment:

    Write default case that returns error code (-1) for invalid letters.

    That’s not how things work in C#; returning a “bad” value to indicate failure is a “worst practice” — it is characteristic of 1970’s style C programming, but not C#.

    The right thing to do here is to either (1) have no error cases at all; if there is no upper case form then just don’t transform the character at all, or (2) throw an exception if the input is bad, or (3) return a nullable char, and return null for the “bad” value.

    Also, the fact that your program takes a ref rather than returning a value is deeply suspicious. A ToDigit method should be computing and returning result not mutating a variable.

    I think whatever course of study you are taking was written decades ago, originally targetted a different language entirely, and was never updated to use modern best practices. I would seriously question the value of such materials.


    Always say (T)(-1) in C# when casting the constant -1 to the type T, rather than (T)-1. If you write it the latter way, the reader can get confused about whether you mean “subtract one from T” or “cast negative one to type T”.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.