How Operators Are Translated

To conclude our discussion about user-defined operators, we take a quick peek at the way their definition gets implemented. As revealed by the static modifier, operators are associated with the type on which they’re defined, rather than with an instance. This has some advantages in terms of compile-time resolution of operators but also limits their expressiveness in terms of runtime dynamism. It’s also not possible to create interfaces that require an implementing type to support certain operators, which is precisely what the mythical INumeric interface would be about (“can Add, Multiply, and so on”). This is a bit of an unfortunate implication of the design of operators.

Operators’ operational nature makes their ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.