1

I want to make a programs to sum 2 number in 2 text box but it's just not working. I don't know exactly why. (And sorry for my bad english skill XD).

Here's the code :

textBox3.Text = Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text);
4
  • 1
    What is the value of textBox1.Text and textBox2.Text? What do you mean by not working? Any exception or error message? Commented Mar 24, 2014 at 13:08
  • The error should be obvious: the sum is not a String, but an Int32. Commented Mar 24, 2014 at 13:10
  • @helb but you can't assign the resulting sum of those two int to a String. Commented Mar 24, 2014 at 13:12
  • @crashmstr Yeah, my mistake sorry. Commented Mar 24, 2014 at 13:13

2 Answers 2

2

Since the result of the operation is not a string but an int you have to call ToString() to assign the string value to textBox3.Text

textBox3.Text = (Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text)).ToString();

Working code:

string y = "";
y = (Convert.ToInt32("3") + Convert.ToInt32("4")).ToString();
Sign up to request clarification or add additional context in comments.

Comments

0

Convert Int32 value to string for display.

textBox3.Text = Convert.ToString(Convert.ToInt32(textBox1.Text) + Convert.ToInt32(textBox2.Text));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.