Equality for Different Types
Equality checks are of particular interest. For reference types, the default behavior of ==
and !=
is to check equality and inequality of the references. In other words, do both the left and right sides of the operator refer to the same object in memory? Often this behavior is not desirable, and operator overloading is used to redefine the meaning of equality, typically based on the underlying data contained by the type. A good example is System.String
, where ==
checks that both strings have the same length and contain the same characters.
In the context of reference types and nullable value types, the equality checks against the null literal should also be considered. For reference types, this is based on checking ...
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.