You have to write like these:
private bool isNumber(string str)
{
    try{
        int.Parse(str);
    }
    catch{
        return false;
    }
    return true;
}Hope it could be help

解决方案 »

  1.   

    我想,XAEP可能是对的.char.isnumber只能判断一个字符是哪种数据类型.不能判断string
    而string中并无此方法.
    不知道还有没有更好的办法,请大家发表下意见.
      

  2.   

    例如:
    private void textBox1_KeyPress(object sender, KeyPressEventArgs e) 

              if(!char.IsDigit(e.KeyChar)) 
                   e.Handled = true; 

      

  3.   

    判断字符串是否是数字,可以如下:
    public bool isNumberic(string strTemp)
    {
        for(int i=0;i<strTemp.Length;i++)
        {
             if(!char.IsDigit(strTemp[i])) 
                   return false; 
        }
        return true;
    }