c#判断字符串是否全部是数字

    /// <summary>判断是否全部是数字</summary>
    private bool IsNumeric(string str)
    {
        if (str == null || str.Length == 0) return false;
        ASCIIEncoding ascii = new ASCIIEncoding();
        byte[] bytestr = ascii.GetBytes(str);

        foreach (byte c in bytestr)
        {
            if (c < 48 || c > 57)
            {
                return false;
            }
        }
        return true;
    }

猜你喜欢

转载自blog.csdn.net/a451319296/article/details/109244713
今日推荐