Overloading in C#

CsharpProgrammingServer Side Programming

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;
}
raja
Published on 14-Aug-2018 16:17:32
Advertisements