You need to convert each textbox to numeric before you add them together rather than after.
Printable View
You need to convert each textbox to numeric before you add them together rather than after.
I figured it out I needed to use Int32.Parse - now it counts.
Int32 Sum = 0;
Sum = Int32.Parse(textBox6.Text) + Int32.Parse(textBox7.Text);
textBox12.Text = Sum.ToString();
I am writing a yahtzee game. I am trying to add the contents of mutliple textboxes. If textbox6 and textbox7 have 2,2 it should be 4, however it is just catnating 22. Any help would be appreciated. I am in my third week of a c# class.
private void button3_Click_1(object sender, EventArgs e)
{
int Sum = 0;
Sum = Convert.ToUInt16(textBox6.Text + textBox7.Text);
textBox12.Text = Sum.ToString();
You need to convert each textbox to numeric before you add them together rather than after.
I thought I was converting before adding by using Convert.ToUInt16 before adding
int Sum = 0;
Sum = Convert.ToUInt16(textBox6.Text + textBox7.Text);
//textBox12.Text = Sum.ToString();
textBox12.Text = Convert.ToString(Sum);