Request.QueryString["id"]
我想判断传过来的值是否为整数,应该怎么办?5  是
abc 不是.
谢谢!!

解决方案 »

  1.   

    try
    {
    Convert.toInt32();
      // 是
    }
    catch(Exception ex)
    {
      //不是
    }
      

  2.   

    xiedan79(还是朋友) 正确完全同意
      

  3.   

    我是用bool来判断的
    if(转换函数(MyValue))
    {
      转换成功
    }
    这个函数是什么呢?
      

  4.   

    //声明一个判断是否整数函数//代码如下
    public bool IsNumeric(string strinput)
    {
        char[] ca=strinput.tochararray();
        for(int i=0;i<strinput.lenght;i++)
        {
          if(ca[i]<'0' || ca[i]>'9')
           {
            return false;
           }
            break;
        }
           return true;     
    }
    //调用函数
    string id=Request.QueryString["id"].tostring();if(IsNumeric(id)==false)
    {
       //不是数字
    }
    else
    {
        //是数字
    }
      

  5.   

    楼上正解vb的isnumeric不太精准。
      

  6.   

    IsNumeric
    if(IsNumeric(Request.QueryString["id"]))
    {
      //转换成功
    }
    bool IsNumeric(string str)
    {
        try
       {
           int i=Convert.toInt32(str);
           return true;
        }
        catch
       {
           return false;
        }   
    }
      

  7.   

    补充 zhangxiaopin(zxp) 一点
    整型最长不能超过8位的。还得判断是否超过8位。
    strinput.lenght<9