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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:39:26+00:00 2026-05-28T19:39:26+00:00

How to fix the errors with characters in C# Employee class I am making.

  • 0

How to fix the errors with characters in C# Employee class I am making. I know how to handle string, int, and double. The char.Parse doesn’t cooperate.

   public static string AskForLastName()
   {
       string inValue;
       Console.Write("Enter last name: ");
       inValue = Console.ReadLine();
       return  inValue; //works fine
   }

    public static char AskForGender()
   {
       char inValue;
       Console.Write("Enter gender: ");
       inValue = Console.ReadLine();//error here for some reason
       return (char.Parse(inValue));//error here for some reason
   }

    public static int AskForNoDependendents()
    {
        string inValue;
        Console.Write("Enter the dependents: ");
        inValue = Console.ReadLine();
        return (int.Parse(inValue));//works fine
    }

    public static double AskForAnnualSalary()
    {
        string inValue;
        Console.Write("Enter annual salary: ");
        inValue = Console.ReadLine();
        return (double.Parse(inValue));//works fine
    }
  • 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-28T19:39:27+00:00Added an answer on May 28, 2026 at 7:39 pm

    Description

    Console.ReadLine returns a string. You can use string[] to get the first character of your string. But you have to make sure that the user inserts at least one character.

    Sample

    public static char AskForGender()
    {
        while (true)
        {
            Console.Write("Enter gender (m/w): ");
            string inValue = Console.ReadLine(); 
            // check that the user inputs a character
            if (!string.IsNullOrEmpty(inValue) && (inValue[0] == 'm' || inValue[0] == 'w'))
                return inValue[0]; 
        }
    }
    

    Update

    My sample covers now that the user inputs m or w.

    Update

    It is homework so…

    If your Teacher ask "But what happens if the user inputs a M instead of m? You should say "It asks the user again".

    If your Teacher asks then "How to make it possible to accept M and m? You should say i can make it case insensitive.

    Sample

    You should use i can use .NET’s .ToUpper() method.

    .ToUpper() – Returns a copy of this string converted to uppercase.

    public static char AskForGender()
    {
        while (true)
        {
            Console.Write("Enter gender (m/w): ");
            string inValue = Console.ReadLine(); 
            // check that the user inputs a character
            if (!string.IsNullOrEmpty(inValue) && (inValue.ToUpper()[0] == 'M' || inValue.ToUpper()[0] == 'W'))
                return inValue.ToUpper()[0]; // returns M or W
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know what this error is, how to fix it, etc. My question is
How I can fix this? Tdm = class(TDataModule) HTTP: TIdHTTP; XMLDoc: TXMLDocument; ... var
ive got an error to fix. its: [FreeTDS][SQL Server]Error converting characters into server's character
How do I fix that error once and for all? I just want to
How do I fix this error? error C2668: 'std::_Tree<_Traits>::end' : ambiguous call to overloaded
How can I fix this error, and install thin or other gems? $ sudo
Please help me to fix the CSS error in profile on my site (IE).
This sure seems like a simple error to fix. However, I somehow can't figure
I got a very similar error to the one below: How can I fix
What causes this error, how can I fix it? Detailed Error Information Module IIS

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.