SEARCH C# PROGRAMMING CODES HERE

Method Overloading

Method Overloading in C#
The benefit of method overloading is that it expands the meaningfulness of the program since you don't have to utilize various names for the same activity. You can perform this task by changing the number of arguments or else you can change the data type of the arguments. Following is the program which demonstrates Method overloading.

Program

using System;

namespace Method_Overloading
{
    class Sum     /*Class Name*/
    {
    /*Methods with same name*/
        public void Result(int print)    
        {

            Console.WriteLine("printing p value = {0}",print);

        }
        public void Result(int x, int y)
        {

            Console.WriteLine("Adding two value x + y = {0}", x + y);

        }

        public void Result(int a, int b, int c)
        {

            Console.WriteLine("Adding three value a + b + c = {0}", a + b + c);

        }
        static void Main(string[] args)
        {
            Sum calculate = new Sum();
            calculate.Result(22);
            calculate.Result(20, 22);
            calculate.Result(50, 24, 22);
            Console.ReadKey();
        }
    }
}

In the above program, you can see we have created a class called"Sum" and also we have characterized three methods with the same name (Result) however, this is called Method Overloading.

Output
printing p value=22
Adding two value x + y =42
Adding three Value a + b + c = 96