Check if string contains only digits

  • Fastest way to check if string contains only digits

    bool IsDigitsOnly(string str)
    {
        foreach (char c in str)
        {
            if (c < '0' || c > '9')
                return false;
        }
    
        return true;
    }
    

    https://stackoverflow.com/questions/7461080/fastest-way-to-check-if-string-contains-only-digits

  • Difference between Char.IsDigit() and Char.IsNumber() in C#