I have a class that implements IComparable.
public class MyClass : IComparable
{
public int CompareTo(MyClass c)
{
return this
One step in that direction would be to use the Sort overload that let's you specify an IComparer
(not an IComparable
, though).
If you already have a lot of IComparable
implementations, it should be trivial to write a general-purpose implementation of IComparer
that compares two IComparable
instances. In fact, I'm a bit surprised such a class doesn't already exist in the BCL, but I haven't been able to find one.
Comparer
comes close, but not quite.