JetBrains Rider
 
Get JetBrains Rider
Get your hands on the new features ahead of the release by joining the Early Access Program for Rider 2025.1! Learn more

Generate Equality Comparer

Last modified: 25 September 2024

IEqualityComparer<T> is a generic .NET interface that allows implementing customized equality comparison for collections.

Creating a comparer class for your type is an alternative to creating Equals() and GetHashCode() methods for the type. The generated comparer class will implement the IEqualityComparer<T> interface and provide custom Equals() and GetHashCode()) methods.

JetBrains Rider provides the Generate equality comparer command to automate generation of the comparer class.

In the example below, this command is used to generate the comparer class based on _radius and _center fields.

Alternatively, you can write an empty comparer class that implements IEqualityComparer<T>, and then pick the corresponding quick-fix from the AltEnter menu:

JetBrains Rider: Generate equality comparer quick-fix