What purpose does the Comparer
class serve if the type that you specify already implements IComparable
?
If I specify Comparer.Defaul
There are a few subtle points here:
IComparable<T>
- it also supports the older (non-generic) IComparable
as a fallback. This means that it can't be expressed just as (for example) a generic constraintNullable<T>
where T
is comparable, even though Nullable<T>
clearly isn't IComparable
or IComparable<T>
List<T>
can provide a Sort
even though it doesn't insist that all T
are sortable; you'd be amazed how quickly the generic constraints would otherwise accumulate