Summary
This chapter wrapped up the discussion of a type’s set of members by looking at operator overloading and user-defined conversions. Care should be taken when deciding on the definition of any of those: It might not be immediately obvious what code means if primitive language operators get a totally different meaning due to excessive overloading. However, there are quite a few cases where overloading operators and providing conversions between types (typically values) is beneficial. Typical samples include mathematical constructs such as a Vector.
Extra care should be taken also when overloading equality operators. More information about this appears in Chapter 14, when you learn about virtual methods, such as System.Object’s Equals
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