ReSharper
 
Get ReSharper
You are viewing the documentation for an earlier version of ReSharper.

Generate Equality Comparer

Last modified: 21 July 2022

ReSharper | Edit | Generate Code | Equality Comparer

Alt+Insert | Equality Comparer (ReSharper_GenerateEqualityComparer)

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.

ReSharper 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 Alt+Enter menu:

ReSharper: Generate equality comparer quick-fix

This feature is supported in the following languages and technologies:

The instructions and examples given here address the use of the feature in C#. For details specific to other languages, see corresponding topics in the ReSharper by language section.