SEARCH C# PROGRAMMING CODES HERE

Methods Overloading

Methods Overloading in C#

Methods Overloading implies characterizing various strategies with the same name with various parameters. By utilizing Method Overloading, we can play out a different task with same strategy name by passing various parameters.
Assume, in the event that we need to overload a method, at that point we have to characterize another technique with the same name yet with various marks. this method is also known as early binding. 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











No comments:

Post a Comment