In the documentation for Compare function in Comparer class it says:
If a implements IComparable, then a. CompareTo (b) is returned; otherwise, if b implements IComparable, then the negated result of b. CompareTo (a) is returned.
But when I test it It seams like it will demand that the first input implements Icomparable. Following code will produce the error:
class Program
{
static void Main(string[] args)
{
Test t1 = new Test();
Test2 t2 = new Test2();
int i = Comparer.Default.Compare(t1,t2);
}
}
class Test
{
}
class Test2 : IComparable
{
public int CompareTo(object obj)
{
return 0;
}
}
Is it just me or is the docs wrong?