在C#中将String转换为整数时出现异常 [英] Exception while converting String to integer in C#
本文介绍了在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.
这篇关于在C#中将String转换为整数时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文