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

  • Home
  • SEARCH
  • 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 3315498
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:21:26+00:00 2026-05-17T22:21:26+00:00

Take this example: customer.Salary = Convert.ToDecimal(string.Format({0}! , Console.ReadLine().ToString())); (1) Why in C# we need

  • 0

Take this example:

customer.Salary = Convert.ToDecimal(string.Format("{0}! ", Console.ReadLine().ToString()));

(1) Why in C# we need to always put .ToString() to get it right?

(2) Convert.To… Doesn’t it creates overheads unnecessarily?

Further in the below given code: It gives error: “Input string was not in a correct format”, after accepting user input.

    // Main begins program execution.
    public static void Main()
    {
        Customer customer = new Customer();
        // Write to console/get input
        Console.Write("Enter customer's salary: ");
        customer.Salary = Convert.ToDecimal(string.Format("{0}! ", Console.ReadLine().ToString()));
        Console.WriteLine("Salary in class variable is: {0}", customer.Salary.ToString()); 
        Console.Read();
    }

    class Customer
    {
        public Decimal Salary { get; set; }
    }

Here again, either I must use:

string sal =  Convert.ToDecimal(string.Format("{0}! ", Console.ReadLine().ToString()));
customer.Salary = Convert.ToDecimal(sal);

Or, I must change the data type itself in the Customer class.

Can this overhead be avoided with anything in Generics?

  • 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-17T22:21:27+00:00Added an answer on May 17, 2026 at 10:21 pm
    1. You do not need to call .ToString().
    2. Yes, it does.

    You’re trying to write

    customer.Salary = Decimal.Parse(Console.ReadLine());
    

    Your current code does the following:

    • Console.ReadLine(): Reads a line from the console, returning a String object.
    • (...).ToString() Returns the same String object
    • string.Format("{0}! ", (...)): Returns a new String object containing the original string followed by !.
    • Convert.ToDecimal((...)): Tries to parse that into a Decimal value.
      Since the string ends with !, it fails
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The questions says everything, take this example code: <ul id=css-id> <li> <something:CustomControl ID=SomeThingElse runat=server
take a look at this example code: public class Comment { private Comment() {
Take a very simple case as an example, say I have this URL: http://www.example.com/65167.html
Take this non-compiling code for instance: public string GetPath(string basefolder, string[] extraFolders) { string
Take the method System.Windows.Forms.Control.Invoke(Delegate method) Why does this give a compile time error: string
Is there a cool way to take something like this: Customer Name - City,
A Lookup in this example is an IList<string> of state abbreviations. Generally, your Domain
Take this example: public class foo { public int[] func() { int arr[] =
So, take this html for example: <ul> <li> <a href=#>Test</a> <ul> <li><a href=#>Test</a></li> <li><a
I don't know how better to describe this. So take this example. var a

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.