Such is the problem, if I enter numbers into TextBox right away, everything is fine, but if I start with a minus, debugging stops. a2 is previously declared in the code as a double variable. What can be done?

private void textBox2_TextChanged(object sender, EventArgs e) { a2 = double.Parse(textBox2.Text); } 
  • the text of the error is needed - iluxa1810
  • System of the system.FormatException 'occurred in mscorlib.dll Additional information: The input string had the wrong format. - Yulia
  • Instead of the Parse() method, use TryParse() - Bulson
  • What do you mean? It requires two arguments, what to pass second? - Yulia
  • This is natural: - not a number. Therefore, if only a minus is entered, then a parsing error. - Alexander Petrov

1 answer 1

 double.TryParse(textBox2.Text, out a2); 
  • Nope, Cannot implicitly convert type 'bool' to 'double' - Yulia
  • one
    @Yulia Yeah. You copied my code incorrectly. I have no assignment a2 = ...; - Igor
  • well, thank you, thank you - Yulia