What is Method Overloading in .Net?,How to use Method Overloading in .Net?


Method overloading means same mehtod name and same return type but number of parameter is defferant ,sequence of parameter may be also defferant.and also datatype of parameter is defferant.

For Example:

namespace CP_Method_overloading
{
    class A
    {
        public int sum(int a, int b)
        {
            return a + b;
        }

        public int sum(int a, int b,int c)
        {
            return a + b+c;
        }

        public double sum(int a, double b)
        {
            return a + b;
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            A obj =new A();
            Console.WriteLine(obj.sum(10, 15));
            Console.WriteLine(obj.sum(10, 15, 20));
            Console.WriteLine(obj.sum(10, 71.52));
        }
    }
}


Output:

25
45
81.52

See Also :
  Follow Me On Facebook

--
/\/ir@\/  <(.'.)>

Comments

Popular posts from this blog