更新时间:2023-11-08 10:26:16
首先关闭,不要使用转换 - 改为使用TryParse,因为它返回成功/失败指示符而不是抛出异常。这允许您向用户报告问题而不是程序失败。
这可能是问题所在:文本框不包含有效整数,即使你删除了所有的逗号。我们无能为力 - 这是一个输入错误,你有责任检测这些错误,让用户在继续之前纠正他的输入。
First off, don't use Convert - use TryParse instead, as it returns a "success / fail" indicator instead of throwing an exception. This allows you to report problems back to your user instead of your program failing.
And that's probably what the problem is: the textbox doesn't contain a valid integer, even after you have removed all the commas. Nothing we can do about that - it's an input error and it's your responsibility to detect those, and get the user to correct his inputs before you continue.