implementando o algoritmo de luhn usando c #

Estou usando o seguinte código para implementar o algoritmo Luhn para verificação de cartão de crédito na linguagem c #, mas não foi possível obter a saída para gerar a soma de verificação, mostrando sua validade: por favor, me ajude.

public class Program
{
    private static void Main(string[]creditcard)
    {
        int sum = 0, d;
        string num ="7992739871";
        int a = 0;

        for (int i = num.Length - 2; i >= 0; i--)
        {
            d = Convert.ToInt32(num.Substring(i, 1));
            if (a % 2 == 0)
                d = d * 2;
            if (d > 9)
                d -= 9;
            sum += d;
            a++;
        }

        if ((10 - (sum % 10) == Convert.ToInt32(num.Substring(num.Length - 1))))
            Console.WriteLine("valid");

        Console.WriteLine("sum of digits of the number" + sum);
    }
}    

questionAnswers(5)

yourAnswerToTheQuestion