在C#中将String转换为整数时出现异常

在C#中将String转换为整数时出现异常

问题描述:



我得到错误:格式异常未处理,输入字符串格式不正确。这个行的


I get error: Format exception was unhandled, Input string was not in a correct format.
for this line:

int right = System.Convert.ToInt32(rightAngleTB.Text);

rightAngleTB是TextBox,值为25(不含)。 >

rightAngleTB is TextBox, the value Text is "25" (without the "").

我真的看不到这个问题:(

I really don´t see the problem :(

你真的应该使用 int.TryParse ,转换更容易,你不会得到例外。

You really should use int.TryParse. It is much easier to convert and you won't get exceptions.