Provides a base class for implementations of the IComparer`1 generic interface.
See Also: Comparer<T> Members
- T
- Documentation for this section has not yet been entered.
Derive from this class to provide a custom implementation of the IComparer`1 interface for use with collection classes such as the SortedList`2 and SortedDictionary`2 generic classes.
The difference between deriving from the Comparer`1 class and implementing the IComparable interface is as follows:
To specify how two objects should be compared by default, implement the IComparable interface in your class. This ensures that sort operations will use the default comparison code that you provided.
To define a comparer to use instead of the default comparer, derive from the Comparer`1 class. You can then use this comparer in sort operations that take a comparer as a parameter.
The object returned by the Comparer`1.Default property uses the IComparable`1 generic interface (IComparable<T> in C#, IComparable(Of T) in Visual Basic) to compare two objects. If type T does not implement the IComparable`1 generic interface, the Comparer`1.Default property returns a Comparer`1 that uses the IComparable interface.