Operator Overloading
Operator overloading creates operator behavior for user-defined types. The best-known example of operator overloading is in C++. The >> and << operators, which are normally the bitwise shift operators, are overloaded to support input and output streams. The >>operator becomes the extraction operator, while the << operator becomes the insertion operator. You can overload operators for any user-defined types in C# to make those types functionally similar to standard or primitive types. However, when overloading operators you should adhere to the general meaning of the operator. For example, don’t overload an operator + for a user-defined type to perform some type of subtraction or deletion. That would definitely confuse users. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access