Operators

We’re almost at the end of our journey through the world of class and struct members. In the previous chapters, we covered fields, properties, methods, and constructors as the member types you’ll be using on a daily basis.

But we haven’t yet covered what could be the most powerful member type in terms of expressiveness for users of our types. Those are operator overloads. Basically, operator overloads are special static methods that can be invoked as a result of using operator syntax such as +, &&, ==, and so on.

Using this feature, it becomes possible to provide more natural-looking and convenient syntax for various operators a type can support on its instances. Vectors are a great example of this:

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.