Method Overloading

In Method Overloading, we define multiple methods with same name, but different parameters like number of parameters, different data types of parameters.

Below is a sample code:

class Program
{
    static void Main(string[] args)
    {
        AddNumbers(3, 4);
        AddNumbers(1.5, 6.7);
        AddNumbers(1256564, 3466757);
        AddNumbers("Hello", "3466757");
    }
    static void AddNumbers(int a, int b)
    { Console.WriteLine("{0} + {1} = {2}", a,b,a+b); }
        
    static void AddNumbers(double a, double b)
    { Console.WriteLine("{0} + {1} = {2}", a, b, a + b); }

    static void AddNumbers(long a, long b)
    { Console.WriteLine("{0} + {1} = {2}", a, b, a + b); }

    static void AddNumbers(string a, string b)
    { Console.WriteLine("{0} + {1} = {2}", a, b, a + b); }
}

Below is the output of above code:

Power Platform Academy

Start or Upgrade your Career with Power Platform

Learn with Akanksha

Python | Azure | AI/ML | OpenAI | MLOps

Design a site like this with WordPress.com
Get started