Summary

In this chapter, we continued our exploration of a type’s set of members by looking at operator overloading and user-defined conversions. Take care 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 examples include mathematical constructs such as a Vector.

Take extra care, as well, when overloading equality operators, making sure that various desired properties and invariants hold. You can find more information about this in Chapter 14, where you ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.