C#验证输入的是否数字

用分解字符的方法实现:
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; 
  } 

其实用正则表达式也可以
static bool IsNumeric(string str)  
{   
   System.Text.RegularExpressions.Regex reg1  
       = new System.Text.RegularExpressions.Regex(@"^[-]?\d+[.]?\d*$");   
   return reg1.IsMatch(str);  
}  

原文地址:https://www.cnblogs.com/adam/p/660809.html