Freigeben über


EqualityComparer<T> Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Provides a base class for implementations of the IEqualityComparer<T> generic interface.

Inheritance Hierarchy

System.Object
  System.Collections.Generic.EqualityComparer<T>

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

Syntax

'Declaration
Public MustInherit Class EqualityComparer(Of T) _
    Implements IEqualityComparer, IEqualityComparer(Of T)
public abstract class EqualityComparer<T> : IEqualityComparer, 
    IEqualityComparer<T>

Type Parameters

  • T
    The type of objects to compare.

The EqualityComparer<T> type exposes the following members.

Constructors

  Name Description
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 EqualityComparer<T> Initializes a new instance of the EqualityComparer<T> class.

Top

Properties

  Name Description
Public propertyStatic memberSupported by Silverlight for Windows PhoneSupported by Xbox 360 Default Returns a default equality comparer for the type specified by the generic argument.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equals(T, T) When overridden in a derived class, determines whether two objects of type T are equal.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetHashCode() Serves as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetHashCode(T) When overridden in a derived class, serves as a hash function for the specified object for hashing algorithms and data structures, such as a hash table.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 IEqualityComparer.Equals Determines whether the specified objects are equal.
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 IEqualityComparer.GetHashCode Returns a hash code for the specified object.

Top

Remarks

Derive from this class to provide a custom implementation of the IEqualityComparer<T> generic interface for use with collection classes such as the Dictionary<TKey, TValue> generic class, or with methods such as List<T>.Sort.

The Default property checks whether type T implements the System.IEquatable<T> generic 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.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.