This topic provides an overview of generic interfaces that provide common functionality across families of generic types.
Generic interfaces provide type-safe counterparts to nongeneric interfaces for ordering and equality comparisons and for functionality that is shared by generic collection types.
Starting with the .NET Framework 4, the type parameters of several generic interfaces are marked covariant or contravariant, providing greater flexibility in assigning and using types that implement these interfaces. See Covariance and Contravariance in Generics.
In the System namespace, the IComparable and IEquatable generic interfaces, like their nongeneric counterparts, define methods for ordering comparisons and equality comparisons, respectively. Types implement these interfaces to provide the ability to perform such comparisons.
In the System.Collections.Generic namespace, the IComparer and IEqualityComparer generic interfaces offer a way to define an ordering or equality comparison for types that do not implement the IComparable or IEquatable generic interface, and they provide a way to redefine those relationships for types that do. These interfaces are used by methods and constructors of many of the generic collection classes. For example, you can pass a generic IComparer object to the constructor of the SortedDictionary class to specify a sort order for a type that does not implement generic IComparable. There are overloads of the ArraySort``1 generic static method and the ListSort instance method for sorting arrays and lists using generic IComparer implementations.
The Comparer and EqualityComparer generic classes provide base classes for implementations of the IComparer and IEqualityComparer generic interfaces, and also provide default ordering and equality comparisons through their respective ComparerDefault and EqualityComparerDefault properties.
The ICollection generic interface is the basic interface for generic collection types. It provides basic functionality for adding, removing, copying, and enumerating elements. ICollection inherits from both generic IEnumerable and nongeneric IEnumerable.
The IDictionary generic interface extends the ICollection generic interface with methods for keyed retrieval. Generic dictionary types in the .NET Framework base class library also implement the nongeneric IDictionary interface.
The IEnumerable generic interface provides a generic enumerator structure. The IEnumerator generic interface implemented by generic enumerators inherits the nongeneric IEnumerator interface; the MoveNext and Reset members, which do not depend on the type parameter T, appear only on the nongeneric interface. This means that any consumer of the nongeneric interface can also consume the generic interface.