Hello everyone,
For a customized class, like I showed in my sample, what will Comparer<>.Default be returned? In my sample, there is System.ArgumentException.
[Code]
class Program
{
class Foo
{
}
static void Main(string[] args)
{
IComparer
Foo f1 = new Foo();
Foo f2 = new Foo();
// System.ArgumentException
FooComparer.Compare(f1, f2);
return;
}
}
[/Code]
thanks in advance,
George
George GeorgePosted Jun 15, 2008, 9:36 AM
Thanks Bechir Bejaoui!
Great article! Two more comments after study,
1.
I think Default.Compare method will convert current instance to IComparable and call IComparable.Compare?
2.
A customized class is not implementing IComparable as default?
regards,
George
Bechir BejaouiPosted Jun 14, 2008, 10:53 AM
It's because compare method is not void it returns an integer.
I invite you to take a look on my article about IComparable(CompareTo) ans IComparer(Compare) I can be helpful for you as well