Programming Examples

Are you a Programmer or Application Developer or a DBA? Take a cup of coffee, sit back and spend few minutes here :)

Tag Archive for ‘Operator Overloading’

Operator Overloading in C#

Fig 2. C# Class With Overloading + Operator

We can overload an operator using the operator keyword followed by the symbol for the operator. In this example, we will overload an + operator to append comma with the strings. Since + is a binary operator, we need two instances of the string. In this example, we will write a class called CommaStr and have a static method with name ‘+’ which acts as an overloaded operator function. Unlike C++, Operator Overloading can be done for very specific operators in C#. You can refer MSDN for list of operators that can support overloading.

Continue Reading →