用例外处理吧,对传入的参数进行相应的转化,失败产生例外,就返回true,否则false

解决方案 »

  1.   

    #region IsInt /// <summary>
    /// 检验一个字符串是否可转换为Int32
    /// </summary>
    /// <param name="str">字符串</param>
    /// <returns>true - 可转换,false - 不可转换</returns>
    public static bool IsInt(string str)
    {
    try
    {
    Int32.Parse(str); return true;
    }
    catch
    {
    return false;
    }
    } #endregion IsInt
      

  2.   

    判断是否为整型数据(仅做参考)public static bool IsInteger(string strTest) 

    double dblNum = 0.0; 
    bool bolIsNumeric = false; 
    try 

    dblNum = Convert.ToDouble(strTest); 
    bolIsNumeric = true; 

    catch 

    bolIsNumeric = false; 

    double dblResidue = 0.0; 
    if (bolIsNumeric == true) 

    dblResidue = dblNum % 1; 
    if (dblResidue != 0) 

    return false; 

    else 

    return true; 


    else 

    return false;