public bool bIsInt(string as_Number)
{
try 
{
int iRet = Convert.ToInt32(as_Number);
}
catch(Exception e)
{
string s = e.ToString();
return false;
}
return true;
}

解决方案 »

  1.   

    包含数字还是全部是数字?
     如果包含数字
     foreach(char cha in yourstring)
     { 
       if (cha>'0'&&cha<'9')
        console.witeline("包含数字")
     }
     如果全部是数字
     foreach(char cha in yourstring)
     { 
       if (cha<'0'||cha>'9')
        console.witeline("不全部是数字")
      else
        全部是数字
     }
      

  2.   

    如果判断是否整型
    try
    {
    int.Parse(yourString);
    }
    catch()
    {
    MessageBox.Show("非数字字符串");
    }
      

  3.   

    public static bool IsNum(string numstr)
    {
    if(numstr.Length==0)
    return false;
    Regex reg = new Regex("^\\d+$");
    if(reg.Match(numstr).Success)
    return true;
    else
    return false;
    }
    orpublic static bool IsNumeric(string str) {
    double resNum;
    bool isNum = Double.TryParse(
    str,System.Globalization.NumberStyles.Float,
    System.Globalization.NumberFormatInfo.InvariantInfo,
    out resNum
    );
    return isNum;
    }