public static bool ifNumber(object sNum, out long outint) 

if (sNum == null) 

outint = 0; 
return false; 

if (long.TryParse(sNum.ToString(), out outint)) 
return true; 
else 
return false; 
}

解决方案 »

  1.   

            private Boolean IsInteger(String strSrc)
            {
                Boolean bRet = false;   
                if (!String.IsNullOrEmpty(strSrc))
                {
                    if (Regex.IsMatch(strSrc, @"[+-]?\d+"))
                    {
                        try
                        {
                            Int64 iTemp = Convert.ToInt64(strSrc);
                            bRet = true;
                        }
                        catch
                        {
                        }
                    }
                }
                return bRet;
            }
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {            string myObj = "a53078323469";            Console.WriteLine(IsNumber(myObj));
                Console.ReadLine();        }        //判断是否数字
            public static bool IsNumber(object sNum)
            {
                long num;   //临时变量
                if (sNum == null)
                {
                    return false;   //如果传入的值为NULL,返回False
                }
                if (long.TryParse(sNum.ToString(), out num))    //尝试转换传入的值
                    return true;    //成功返回True
                else
                    return false;   //失败返回False
            }
        }
    }
      

  3.   

    刚才的正则有点错误,这次的应该可以了        private Boolean IsInteger(String strSrc)
            {
                Boolean bRet = false;
                if (!String.IsNullOrEmpty(strSrc))
                {
                    if (Regex.IsMatch(strSrc, @"^[+-]?\d+$"))
                    {
                        try
                        {
                            Int64 iTemp = Convert.ToInt64(strSrc);
                            bRet = true;
                        }
                        catch
                        {
                        }
                    }
                }
                return bRet;
            }
      

  4.   

    public void IsNum(string str)
            {
                int b = 123;
                if (int.TryParse(str, out b))
                {
                    Response.Write(b);
                }
                else
                {
                    Response.Write("Failed to Parse to Int");
                }
            }
      

  5.   

    你所说的整数有要求么 比如  000001 算么
    有最大/小数的限制么.......如果没什么特别要求  用Convert.ToInt32/64 或 int.TryParse ... 等尝试转换就可以了