标识字符串是否为数字如果我有这些条件:"abc" = false"123" = true"ab2" = false有没有命令,比如IsNumeric()或者其他的东西,可以识别一个字符串是否是一个有效的数字?
3 回答

摇曳的蔷薇
TA贡献1793条经验 获得超6个赞
int n;bool isNumeric = int.TryParse("123", out n);
更新
var isNumeric = int.TryParse("123", out int n);

慕村225694
TA贡献1880条经验 获得超4个赞
input
TryParse
Regex.IsMatch(input, @"^\d+$")
^
+
$
.
Regex.IsMatch(input, @"\d")
编辑:

白衣染霜花
TA贡献1796条经验 获得超10个赞
stringTest.All(char.IsDigit);
true
float
false
请注意: stringTest
- 3 回答
- 0 关注
- 413 浏览
添加回答
举报
0/150
提交
取消