HI,
how to add a negative numbers in c#.
ex. one textbox1 have a 10 value and another textbox2, i am entering -2 value. but when i enter "-" sign or -2 the error is occur. ie. inpute string was not in correct format. all this is done on textbox2_TextChanged event. i am using Asp.net 2.0 (Window Application) and C#.
Adding Negative Numbers in c#
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Kirtan PatelRank #292 · 8.6K reputationPosted Dec 18, 2009, 3:44 AM EST
here is code you need ...
if my answer helps you then check "Do you like this answer" check box please :)
private void button1_Click(object sender, EventArgs e)
{
int number1 = int.Parse(textBox1.Text);
int number2 = int.Parse(textBox2.Text);
int total = number1 + number2;
MessageBox.Show(total.ToString());
}
Hiren SoniRank #694 · 3.5K reputationPosted Dec 18, 2009, 4:05 AM EST
paul daniel189 reputationPosted Dec 22, 2009, 11:12 PM EST
Try this simple method
TextBox3.Text =( int.Parse (TextBox1.Text) + int.Parse (TextBox2.Text)).ToString();
or
TextBox3.Text=Convert.ToString(Convert.ToInt32(TextBox1.Text)+Convert.ToInt32(TextBox2.Text));