In c#, Method Overloading means defining a multiple methods with same name but with different parameters. By using Method Overloading, we can perform a different tasks with same method name by passing different parameters.

Suppose, if we want to overload a method in c#, then we need to define another method with same name but with different signatures. In c#, the Method Overloading is also called as compile time polymorphism or early binding.

public class Calculate
public void AddNumbers(int a, int b)
Console.WriteLine("a + b = {0}", a + b);

public void AddNumbers(int a, int b, int c)
Console.WriteLine("a + b + c = {0}", a + b + c);

A class can have several implementations, orĀ overloads, of the same method that differ in the number of parameters or parameter types.

To overload a method:

public int sampleMethod(string sampleParam) {};   
public int sampleMethod(int sampleParam) {}
Last modified: March 20, 2019



Write a Reply or Comment