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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:06:51+00:00 2026-06-15T16:06:51+00:00

label1 is ok, but label2 is not ok and get error , private void

  • 0

label1 is ok,
but label2 is not ok and get error ,

private void button1_Click(object sender, EventArgs e)
{
    double a = Convert.ToDouble(textBox1.Text);
    double b = Convert.ToDouble(textBox2.Text);
    double z = Convert.ToDouble(label1.Text);

    label1.Text = (a + b).ToString(); // it is ok
    label2.Text = (z + a).ToString(); // not ok and get error    
}
  • 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-15T16:06:53+00:00Added an answer on June 15, 2026 at 4:06 pm

    Yes, there are a few syntax errors. Not only that, but once you get your code to compile and run, you will a runtime error. I decided it is easiest to correct the code and comment on what the problem was and how and in some cases, why you should do it a different way.

    Remember, even with the code I provide, you may still receive runtime (notcompile time) errors based on what the end user enters. Use the pattern I supplied to make the additonal adjustments (read the comments next to the new and old code.

            double a = Convert.ToDouble(textBox1.Text); // Tip: I would recomment using Double.TryParse() instead of what you have here unless you know a number will always be in this box (I will provide an example with your 'z')
            double b = Convert.ToDouble(textBox2.Text); // Tip: I would recomment using Double.TryParse() instead of what you have here unless you know a number will always be in this box (I will provide an example with your 'z')
            /* double z = Convert.ToDouble(label1.Text);  /* First off, you need to correct your syntax errors:
                                                        * You had: double z - Convert.toDouble(label1.Text);   Notice the minus (-) and not equal (=) sign
                                                        *  You also need to capatilize the 'T' in what you have 'toDouble' and change it to 'ToDouble' 
                                                        *  Second off, you need to correct your runtime errors:
                                                        *  In this line, you are trying to convert something in this label (lbl1) to a double.  This will not work because at 
                                                        *  runtime, there is nothing in this label because it has no text. Incase you don't know, if you are using Visual Studio, you should 
                                                        *  put a break point on this line by pressing F9.  Then when you run your application, Visual Studio will halt/pause here so you can see 
                                                        *  value of label1.Text by moving your mouse over it.  You will notice it is "" which cannot be converted 
                                                        *  There are a few possible solutions that you can emply to make this work but I will show you my prefered method below: */
            double z;
            bool didItParseDouble = Double.TryParse(label1.Text, out z); /* The first paramater is what you want to try and parse.. in this case, you are trying to parse a label.
                                                  * If it can parse it, it will assign the value to the out parameter which is 'z'  You must preceed this with the out keyword!
                                                   * If it can't parse, it will */
            if (didItParseDouble)
            {
                // It parsed/convered (although parse and convert are technically different)
                // When you first run the application, you will NOT hit this block of code because ditItParse is false because label1.Text is "".  (Put a break point here and you will see)
                // This is where you should put your calcuations at.  Don't forget, though, that if the user enters nothing for the first or second textbox, your code as is will fail so you should do a try parse there as well!
                // There are many ways to handle this, various patters, this is just one.  You can even put the Double.TryParse(...) in the if conditional statement!
            }
            else
            {
                // It couldn't parse so you could put some error handling here if you would like.
            }
    
    
            label1.Text = (a + b).ToString(); // C# is case sensitive so your code won't compile!  You had:  label1.TexT = (a + b).ToString(); 
    
            label2.Text = ( z + a).ToString(); // Now that z is a valid double it should work.    //not ok and get error  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

str = "&&"; label1.Text = str; but it only shows "&". How do I
I have a method -(NSArray *) updateLabel:(id)sender { [somelabel setStringValue:@test]; } But the label
I'm not exactly sure on my lambda's yet but why isn't the following working?
I am trying to make my first AJAX Control and I get error. I
i am not sure if my design have flaw but would like to know
I am using a WrapPanel with an Image and Label, but the Label shows
How can I create an UIBarButtonItem without any border, but just a label inside?
sending text to label and number to int from tabelview to viewcontroller but it
I Made label to had value from database and linked it . but the
I set x_label_skip to skip labels, but it still tries to display the very

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.