06-06-2013, 04:14 PM
Operator Overloading
Operator Overloading.pptx (Size: 56.83 KB / Downloads: 22)
Defining Operator Overloading
To define additional task to an operator, we must specify what it means in relation to the class
This is done with the help of special method called operator method
The general form of this method is
Public static retval operator op (arglist)
Overloading Comparison Operator
C# supports six comparison in three pair
== and ! =
> and < =
< and >=
The significance of pairing is :
Within each pair, second operator should always give exactly the opposite result to the first
That is, whenever first returns true, the second return false
C# always requires us to overload the comparison operator in pair, means if we overload = =, than we must overload ! = also, otherwise it is an error
There is fundamental difference between overloading comparison operator and arithmetic operator
Comparison operator must return bool type value