This program inputs two integers and then the user can choose to Add them or Subtract them. I'm using a Visual C# book by Joyce Farrell. But when I run the program I'm getting an unhandled exception error.
Unable to cast object of type "System.Windows.Forms.Textbox to type System.Convertible.
My code is this:
Unable to cast object of type "System.Windows.Forms.Textbox to type System.Convertible.
My code is this:
C#:
private void buttonAdd_Click(object sender, EventArgs e)
{
int firstNumber;
int secondNumber;
int sum;
firstNumber = Convert.ToInt32(textBoxFirstNumber);
secondNumber = Convert.ToInt32(textBoxSecondNumber);
sum = firstNumber + secondNumber;
labelAnswer.Text = "The sum is " + sum;
}
Attachments
Last edited by a moderator: