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#.
Loading
Kirtan PatelPosted Dec 18, 2009, 8:44 AM
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());
}
paul danielPosted Dec 23, 2009, 4:12 AM
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));
Hiren SoniPosted Dec 18, 2009, 9:05 AM