How to convert binary number to decimal in C# using method.

using System;

    class BinToDec
    {
        static void Main(string[] args)
        {
            string binary = "101";
            Console.WriteLine(BinaryToDecimal(binary)); // will return 5

        }

        private static long BinaryToDecimal(string binary)
        {
            long decimalNum = 0;
            for (int i = binary.Length - 1, pow = 0; i >= 0; i--, pow++)
            {
                decimalNum += int.Parse(binary[i].ToString()) * (long)Math.Pow(2, pow);
            }

            return decimalNum;
        }
    }