Here's code I have written for a simple event based adder, this is the error I constantly get: Object reference not set to an instance of an object.
I am a beginner, so what's my error here? What am I missing? Thanks.
private void txtTwo_TextChanged(object sender, TextChangedEventArgs e)
{
int numberOne, numberTwo, number3;
if (int.TryParse(txtOne.Text, out numberOne))
{
// DO NOTHING
}
else
{
MessageBoxButton buttons = MessageBoxButton.OK;
MessageBoxImage icon = MessageBoxImage.Error;
MessageBox.Show("Not An Integer! Only Integers Allowed !", "Error : First Number", buttons, icon);
txtOne.Clear();
}
if (int.TryParse(txtTwo.Text, out numberTwo))
{
//DO NOTHING
}
else
{
MessageBoxButton buttons2 = MessageBoxButton.OK;
MessageBoxImage icon2 = MessageBoxImage.Error;
MessageBox.Show("Not An Integer! Only Integers Allowed !", "Error : Second Number", buttons2, icon2);
txtTwo.Clear();
}
number3 = numberOne + numberTwo;
string num3 = number3.ToString();
txtOut.Text = num3;
}