System.Xml.XmlConverter.TryParseInt64 C# (CSharp) Method

TryParseInt64() private static method

private static TryParseInt64 ( byte chars, int offset, int count, long &result ) : bool
chars byte
offset int
count int
result long
return bool
        private static bool TryParseInt64(byte[] chars, int offset, int count, out long result)
        {
            result = 0;
            if (count < 11)
            {
                int value;
                if (!TryParseInt32(chars, offset, count, out value))
                    return false;
                result = value;
                return true;
            }
            else
            {
                long value = 0;
                int offsetMax = offset + count;
                if (chars[offset] == '-')
                {
                    for (int i = offset + 1; i < offsetMax; i++)
                    {
                        int digit = (chars[i] - '0');
                        if ((uint)digit > 9)
                            return false;
                        if (value < long.MinValue / 10)
                            return false;
                        value *= 10;
                        if (value < long.MinValue + digit)
                            return false;
                        value -= digit;
                    }
                }
                else
                {
                    for (int i = offset; i < offsetMax; i++)
                    {
                        int digit = (chars[i] - '0');
                        if ((uint)digit > 9)
                            return false;
                        if (value > long.MaxValue / 10)
                            return false;
                        value *= 10;
                        if (value > long.MaxValue - digit)
                            return false;
                        value += digit;
                    }
                }
                result = value;
                return true;
            }
        }