I have 3 textboxes in which I write numbers and 1 in which is the result. If I write numbers in TextBoxA and TextBoxB insted of adding them together after I press equal button it put them next to eachother.
[
]
I tried this code:
`
private void EqualsButton_Click(object sender, EventArgs e)
{
OutputTextBox.Text = ($"{InputTextBoxA.Text + InputTextBoxB.Text}");
}
`
>Solution :
You need to convert text fields to int and after for the answer back to the text.
If you did not enter a value, then there "" is considered as 0 when adding.
private void EqualsButton_Click(object sender, EventArgs e)
{
OutputTextBox.Text = Convert.ToString(
Convert.ToInt32(InputTextBoxA.Text == "" ? "0" : InputTextBoxA.Text)
+ Convert.ToInt32(InputTextBoxB.Text == "" ? "0" : InputTextBoxB.Text));
}