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
TThe 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
elementComparerIEqualityComparer<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
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
Methods
Equals(IEnumerable<T>?, IEnumerable<T>?)
Determines whether the specified objects are equal.
public bool Equals(IEnumerable<T>? x, IEnumerable<T>? y)
Parameters
xIEnumerable<T>The first object of type
Tto compare.yIEnumerable<T>The second object of type
Tto compare.
Returns
GetHashCode(IEnumerable<T>)
Returns a hash code for the specified object.
public int GetHashCode(IEnumerable<T> obj)
Parameters
objIEnumerable<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
objis a reference type andobjis null.