Method overloading is process in which it allow the programmer to use multiple methods with the same name in same class. But the methods are differentiate with their number and type of argument that passed in methods. Method overloading is a example of Polymorphism of object oriented programming language.
Method overloading can be used with the following point.
• Different number of parameter of methods .
• Different data type of parameter passed in method.
• Different sequence of parameter that passed in method.
Example:
using System;
public class Program
{
public static void Main()
{
MethodOveloadingExample m=new MethodOveloadingExample();
Console.WriteLine( m.sum(1,2,5));
}
public class MethodOveloadingExample
{
public int sum(int a, int b) //two int type Parameters method
{
return a+b;
}
public int sum(int a, int b,int c) //three int type Parameters with same method same as above
{
return a+b+c;
}
public float sum(float a, float b)
{
return a+b;
}
}
}
OUTPUT:
8
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Method Overloading in C#:
Method overloading is process in which it allow the programmer to use multiple methods with the same name in same class. But the methods are differentiate with their number and type of argument that passed in methods. Method overloading is a example of Polymorphism of object oriented programming language.
Method overloading can be used with the following point.
• Different number of parameter of methods .
• Different data type of parameter passed in method.
• Different sequence of parameter that passed in method.
Example:
OUTPUT:
8