在C#中应尽量副渔获物可用于为数字测试? [英] In C# should try-catch be used for is-numeric testing?

查看:112
本文介绍了在C#中应尽量副渔获物可用于为数字测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说过,使用异常捕获不是数字测试建议的做法

I have heard that using exception trapping is not a recommended practice for number testing.

例如:

bool isnumeric
try
{
int i = int.parse(textbox1.text);
isnumeric = true;
}

catch {isnumenric=false}



有我可以测试在C#号一些其他的方式?

Is there some other way that I could test for numbers in C#?

推荐答案

是尝试使用

int i;    
bool success = Int32.TryParse(textBox1.text, out i);



的TryParse 方式基本上没有你在上面做什么。

The TryParse method basically does what you are doing above.

这篇关于在C#中应尽量副渔获物可用于为数字测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆