
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What is overloading in C#?
C# provides two techniques to implement static polymorphism −
- Function overloading
- Operator overloading
Function Overloading
Two or more than two methods having the same name but different parameters is what we call function overloading in C#.
Function 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 function 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
Operator Overloading
Overloaded operators are functions with special names the keyword operator followed by the symbol for the operator being defined.
The following shows which operators can be overloaded and which you cannot overload −
Sr.No | Operator & Description |
---|---|
1 | +, -, !, ~, ++, -- These unary operators take one operand and can be overloaded. |
2 | +, -, *, /, % These binary operators take one operand and can be overloaded. |
3 | ==, !=, <, >, <=, >= The comparison operators can be overloaded. |
4 | &&, || The conditional logical operators cannot be overloaded directly. |
5 | +=, -=, *=, /=, %= The assignment operators cannot be overloaded. |
6 | =, ., ?:, -<, new, is, sizeof, typeof These operators cannot be overloaded |
- Related Articles
- What is Overloading in Java?
- What is method overloading in Java?
- What is function overloading in JavaScript?
- What is constructor overloading in Java?
- What is method overloading in C#?
- What is method overloading in PHP?
- What is overloading a unary operator in C++?
- What is overriding and overloading under polymorphism in java?
- What is runtime polymorphism or dynamic method overloading?
- What are base overloading methods in Python?
- What is overloading? What happens if we overload a main method in java?
- What is the difference between method overloading and method hiding in Java?
- Overloading in C#
- Overloading in java programming
- Overloading Operators in Python

Advertisements