string s = "1234";
double resNum;
bool isNum = Double.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out resNum );

解决方案 »

  1.   

    做个循环,或者试着转换成int,double
      

  2.   

    string s = "1234";
    int i;
    try
    {
        i=Convert.ToInt32(s);
        //是数字
    }
    catch
    {
        //不是数字
    }
      

  3.   

    问一句,c#里是不是没有功能类似于isnumber,但参数是一个字符串的函数?
      

  4.   

    try
    {
        i=Convert.ToInt32(s);
        //是数字
    }
    catch
    {
        //不是数字
    }
    不行啊,即使s不是数字,catch里的语句也没反应,是不是该有参数?catch(??)
      

  5.   

    你做一个函数:
    bool AfxIsNumber(string s)
    {
       try{ Int32.Parse(s); return true; } catch {return false};
    }
      

  6.   

    改进一下函数:
    bool AfxIsNumber(string s)
    {
       try{ Int32.Parse(s); return true; } catch {};
       try{ Int64.Parse(s); return true; } catch {};
       ...
       //最后一次尝试
       try{ Double.Parse(s); return true; } catch {return false};
    }
      

  7.   

    string s="sf";
    int i;
    try
    {
        i=Convert.ToInt32(s);
        //是数字
        Console.WriteLine(i.ToString());
    }
    catch(FormatException e)
    {
        Console.WriteLine(e.ToString());
    }以上代码运行通过,没有任何问题