Table of Contents

Class EnumerableEqualityComparer<T>

Namespace
Utils.Collections
Assembly
Utils.dll

A comparer for enumerables that allows comparison of sequences based on custom or default equality logic for each element.

If both sequences implement IReadOnlyList<T>, the comparison first checks Count for an early exit. Uses Span<T> when applicable for performance.

public sealed class EnumerableEqualityComparer<T> : IEqualityComparer<IEnumerable<T>>

Type Parameters

T

The type of elements in the enumerable.

Inheritance
EnumerableEqualityComparer<T>
Implements
Inherited Members
Extension Methods

Constructors

EnumerableEqualityComparer(IEqualityComparer<T>)

Initializes a new instance of the EnumerableEqualityComparer<T> class using a provided element equality comparer.

public EnumerableEqualityComparer(IEqualityComparer<T> elementComparer)

Parameters

elementComparer IEqualityComparer<T>

An equality comparer for elements of type T.

EnumerableEqualityComparer(Func<T, T, bool>, Func<T, int>)

Initializes a new instance of the EnumerableEqualityComparer<T> class using a provided element equality comparer.

public EnumerableEqualityComparer(Func<T, T, bool> comparer, Func<T, int> hasher = null)

Parameters

comparer Func<T, T, bool>
hasher Func<T, int>

Properties

Default

A thread-safe, cached instance of EnumerableEqualityComparer<T> using the default comparison logic for elements.

public static EnumerableEqualityComparer<T> Default { get; }

Property Value

EnumerableEqualityComparer<T>

Methods

Equals(IEnumerable<T>?, IEnumerable<T>?)

Determines whether the specified objects are equal.

public bool Equals(IEnumerable<T>? x, IEnumerable<T>? y)

Parameters

x IEnumerable<T>

The first object of type T to compare.

y IEnumerable<T>

The second object of type T to compare.

Returns

bool

true if the specified objects are equal; otherwise, false.

GetHashCode(IEnumerable<T>)

Returns a hash code for the specified object.

public int GetHashCode(IEnumerable<T> obj)

Parameters

obj IEnumerable<T>

The object for which a hash code is to be returned.

Returns

int

A hash code for the specified object.

Exceptions

ArgumentNullException

The type of obj is a reference type and obj is null.