EqualityComparer<'T>.Default Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Returns a default equality comparer for the type specified by the generic argument.

Namespace:   System.Collections.Generic
Assembly:  mscorlib (in mscorlib.dll)

static member Default : EqualityComparer<'T> with get

Property Value

Type: System.Collections.Generic.EqualityComparer<'T>

The default instance of the EqualityComparer<'T> class for type T.

The Default property checks whether type T implements the System.IEquatable<'T> interface and, if so, returns an EqualityComparer<'T> that uses that implementation. Otherwise, it returns an EqualityComparer<'T> that uses the overrides of Object.Equals and Object.GetHashCode provided by T.

The following example creates two dictionary collections of type Box. Both dictionaries are created with the constructor that takes an EqualityComparer<'T> as a parameter.

To determine the equality of dictionary keys, the boxesByDim dictionary uses an equality comparer (BoxEqDimensions) that uses the implementation of the IEquatable<'T>.Equals method in the Box class. Two boxes are considered equal if their dimensions are the same.

The boxesByVol dictionary uses an equality comparer (BoxEqVolume) that defines equality by volume. Two boxes are considered equal if their volumes are the same.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top