Operator Overloading - CSharp Custom Type

CSharp examples for Custom Type:Operator Overloading

Introduction

Operators can be overloaded to provide more natural syntax for custom types.

The following symbolic operators can be overloaded:

+ (unary)  - (unary) !    ~  ++
 --        +         -    *  /
 %          &          |   ^  <<
 >>         ==        != >  <
 >=         <=

The following operators are also overloadable:

  • Implicit and explicit conversions (with the implicit and explicit keywords)
  • The true and false operators.

The following operators are indirectly overloaded:

The compound assignment operators (e.g., +=, /=) are implicitly overridden by overriding the noncompound operators (e.g., +, /).

The conditional operators && and || are implicitly overridden by overriding the bitwise operators & and |.


Related Tutorials