如何检查字符串是否为数字.我正在验证手机号码,它应该有10位数字,并且只能采用数字格式.
string str="9848768447"
if(str.Length==10 && Here I need condition to check string is number or not)
{
//Code goes here
}
Run Code Online (Sandbox Code Playgroud)
我是编程新手.请帮我
用途int.TryParse:
int i;
if(str.Length==10 && int.TryParse(str, out i))
{
//Code goes here
}
Run Code Online (Sandbox Code Playgroud)
另一种与unicode数字有关的方法是使用Char.IsDigit:
if(str.Length==10 && str.All(Char.IsDigit))
{
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3506 次 |
| 最近记录: |