我听说使用异常捕获不是数字测试的推荐做法。
例如:
bool isnumeric
try
{
int i = int.parse(textbox1.text);
isnumeric = true;
}
catch {isnumenric=false}
有没有其他方法可以在 C# 中测试数字?
最佳答案
是的,尝试使用
int i;
bool success = Int32.TryParse(textBox1.text, out i);
TryParse 方法基本上完成您在上面所做的事情。
关于c# - 在 C# 中,try-catch 应该用于数字测试吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/496519/