Method Overloading in C# with example   

Method Overloading is the process of creating multiple methods with same name but with different parameters in a class. Otherwise, we cannot have methods with the same name until and unless parameter list is different .

0 365 Technology | C-Sharp
Fri Dec 28 , 2018

Method Overloading can be achieved if any criteria satisfy:

  • The data types of Parameter can be different.
  • The number of Parameters can be different.
  • The order of Parameters can be different.

Example

  
using System;
public class Method_Overloading
{
	public void sum(int a, int b)
	{
		Console.WriteLine("a + b = {0}", a + b);
	}
	public void sum(int a, int b, int c)
	{
		Console.WriteLine("a + b + c = {0}", a + b + c);
	}
	public static void Main(string[] args)
	{	
		Method_Overloading mo = new  Method_Overloading();
		mo.sum(5, 5);
		mo.sum(5, 5, 5);
	}
}

Output

a + b = 10
a + b + c = 15	


Subscribe & Get Regular Updates On Your E-mail