C# Operator Overloading

Tutorial Difficulty Level    

You can redefine or overload most of the built-in operators available in C#. Thus a programmer can use operators with user-defined types as well. Overloaded operators are functions with special names the keyword operator followed by the symbol for the operator being defined. similar to any other function, an overloaded operator has a return type and a parameter list.

For example, go through the following function:

The above function implements the addition operator (+) for a user-defined class Box. It adds the attributes of two Box objects and returns the resultant Box object.

The following program shows the complete implementation:

When the above code is compiled and executed, it produces the following result:

This link describes the overload ability of the operators in C#.

In the light of the above, let us extend the preceding example, and overload few more operators:

When the above code is compiled and executed, it produces the following result:
CategoriesC#