![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is method overloading in C#?
Two or more than two methods having the same name but different parameters is what we call method overloading in C#.
Method overloading in C# can be performed by changing the number of arguments and the data type of the arguments.
Let’s say you have a function that prints multiplication of numbers, then our overloaded methods will have the same name but different number of arguments −
public static int mulDisplay(int one, int two) { } public static int mulDisplay(int one, int two, int three) { } public static int mulDisplay(int one, int two, int three, int four) { }
The following is an example showing how to implement method overloading −
Example
using System; public class Demo { public static int mulDisplay(int one, int two) { return one * two; } public static int mulDisplay(int one, int two, int three) { return one * two * three; } public static int mulDisplay(int one, int two, int three, int four) { return one * two * three * four; } } public class Program { public static void Main() { Console.WriteLine("Multiplication of two numbers: "+Demo.mulDisplay(10, 15)); Console.WriteLine("Multiplication of three numbers: "+Demo.mulDisplay(8, 13, 20)); Console.WriteLine("Multiplication of four numbers: "+Demo.mulDisplay(3, 7, 10, 7)); } }
Output
Multiplication of two numbers: 150 Multiplication of three numbers: 2080 Multiplication of four numbers: 1470
Advertisements