5 TYPES OF EQUALITY
Programs frequently compare variables to see if their values are equal, although this operation is often overlooked because it’s done implicitly. Every type inherits the Equals method from the object base class, so given any two values x and y, the expression x.Equals(y) is always valid.
C# also provides ==, or the equals-equals operator, for explicitly checking equality of two values. Using == for comparisons differs from using the Equals method in multiple ways. In this chapter, we’ll look at why C# supports two techniques for equality comparison and how each is affected by the differences between types.
We’ll explore ...
Get The C# Type System 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.