Posts about the .NET Framework. See also csharp.

Types behaving badly

14 Apr 2018 equality dotnet

At the opening of this series I wrote about how a correct implementation of equality is essential for the correct behaviour of many fundamental .NET types - including List, HashSet and Dictionary. Here’s an example to show how they can break.

Implementing Value Equality

7 Apr 2018 equality dotnet

Building on our implementation of entity equality, we are now in a position to implement value equality. This is more complex because it tends to have a greater number of factors to consider.

Implementing Entity Equality

31 Mar 2018 equality dotnet

Now that we’ve talked about the importance of implementing equality, the different kinds of equality, and about the contracts required of our implementations, we can get down to actually writing some code.

Equality and GetHashCode

24 Mar 2018 equality dotnet

After symmetry, another aspect of the equality contract is .GetHashCode(). When you first override .Equals(object), the C# compiler will helpfully remind you that you must also override .GetHashCode().

Types of Equality

10 Mar 2018 equality dotnet

Having established the importance of equality in .NET, we can look at the different kinds of equality that you might encounter. There are three - Reference, Value and Entity equality.

Older posts

Why is Equality important in .NET?  03 Mar 2018
Invalid Build Configuration: Debug|BNB  14 May 2011
Intersect and Except  24 Jul 2008
Streams in .NET  26 Dec 2003
Bitmap cloning in .NET  11 Dec 2003
Streams in .NET  20 Nov 2003