value equality
Treating two objects as equal when their members hold equal values, even if they are separate objects.
In more detail
Records get value equality generated for them. A class gets it only if you override Equals and GetHashCode, and even then == still compares references unless you also define the operator.
Related terms
- reference equality — Comparing two references to see whether they point to the very same object, rather than to objects with equal contents.
- record — A C# type declared with the record keyword for data, for which the compiler generates a constructor, properties, value equality, a readable ToString and with-expression copying.
- GetHashCode — The method that returns a number summarising an object, used by hash-based collections such as Dictionary and HashSet to find it quickly.
Taught in
- Classes, Interfaces, and Object-Oriented C# — Modern .NET Core, C# & Enterprise Microservices
- Records, Pattern Matching, and Modern C# — Modern .NET Core, C# & Enterprise Microservices