Overloading in C#


Overloading is of two types in C#.

Function Overloading

You can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list.

Let us see an example −

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) { }

Operator Overloading

Overloaded operators are functions with special names. The keyword operator is followed by the symbol for the operator being defined.

public static Box operator+ (Box b, Box c) {
   Box box = new Box();
   box.length = b.length + c.length;
   box.breadth = b.breadth + c.breadth;
   box.height = b.height + c.height;
   return box;
}

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 21-Jun-2020

180 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements