C# Member overloading

tutorial and example
tutorial and example

If we define two members in a class with the same name then it’s called member overloading. Advantage of member overloading is the thing that we don’t need to give different names to the members of the same meaning and are defined for the same purposes.

In C#, we can overload constructors, methods and index properties since they have parameters defined in their signature.

C# Method overloading:

In a class, if we defined two methods with the same name but different signature then it’s called method overloading. To overload a method we need to:

  1. Change the number of parameters.
  2. Change the data type of parameters.

C# Method overloading example: by changing number of parameters

C# Method Overloading Example: by changing data type of parameters

C# Type Promotion in method overloading:

In C#, one data type is promoted to another if no matching is found between function call and function definition.

Let’s see an example of type promotion in method overloading. The float In the function call is automatically promoted to double of function signature defined.

Output