Aqueduct.Extensions.Validation.IsValidLuhn C# (CSharp) Method

IsValidLuhn() public static method

Determines whether the specified int array passes the Luhn algorith
public static IsValidLuhn ( this digits ) : bool
digits this The int array to evaluate
return bool
        public static bool IsValidLuhn(this int[] digits)
        {
            int sum = 0;
            bool alt = false;
            for (int i = digits.Length - 1; i >= 0; i--)
            {
                if (alt)
                {
                    digits[i] *= 2;
                    if (digits[i] > 9)
                        digits[i] -= 9; // equivalent to adding the value of digits
                }
                sum += digits[i];
                alt = !alt;
            }
            return sum % 10 == 0;
        }