其实用正则表达式也可以
static bool IsNumeric(string str)
  {
   if (str==null || str.Length==0)
    return false;
   foreach(char c in str)
   {
    if (!Char.IsNumber(c))
    {
     return false;
    }
   }
   return true;
  }

正则表达的写法是:
C#验证输入的是否数字的方法static bool IsNumeric(string str) 
{  
   System.Text.RegularExpressions.Regex reg1 
       = new System.Text.RegularExpressions.Regex(@"^[-]?\d+[.]?\d*$");  
  
return reg1.IsMatch(str); 
}
 
C#验证输入的是否数字的方法

相关文章:

  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-22
  • 2021-12-03
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2021-05-27
相关资源
相似解决方案