现在的位置: 首页 > 综合 > 正文

C#判断是否是数字

2013年10月15日 ⁄ 综合 ⁄ 共 597字 ⁄ 字号 评论关闭

      /// <summary>
        /// 判断是否是数字
        /// </summary>
        /// <param name="str">字符串</param>
        /// <returns></returns>
        private bool IsNumeric(string str) 
        {
            if (str == null || str.Length == 0)
                return false;
            System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
            byte[] bytestr = ascii.GetBytes(str);
            foreach(byte c in bytestr) 
            { 
                if (c < 48 || c > 57)  
                { 
                    return false; 
                } 
            } 
            return true; 
        }

【上篇】
【下篇】

抱歉!评论已关闭.