Before I go reinventing the wheel, is there some framework way of creating an IComparer<T>
from a Func<T,T,int>
?
EDIT
IIRC (it's been a while) Java supports anonymous interface implementations. Does such a construct exist in C#, or are delegates considered a complete alternative?
In the upcoming .NET4.5 (Visual Studio 2012) this is possible with the static factory method Comparer<>.Create
. For example
IComparer<Person> comp = Comparer<Person>.Create(
(p1, p2) => p1.Age.CompareTo(p2.Age)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With