views:

166

answers:

3

The .NET framework provides a few handy general-use delegates for common tasks, such as Predicate<T> and EventHandler<T>.

Is there a built-in delegate for the equivalent of CompareTo()?

The signature might be something like this:

delegate int Comparison<T>(T x, T y);

This is to implement sorting in such a way that I can provide a lambda expression for the actual sort routine (ListView.ListViewItemSorter, specifically), so any other approaches welcome.

A: 

Look for: System.Collections.Generic.Comparer<T>

JoshBerke
Oops - had upvoted that, but Comparer<T> isn't the delegate type - that's System.Comparison<T> as suggested by Joel. Comparer is still useful, but it's based on the IComparer<T> interface.
Jon Skeet
Ohh bah humbug your right, darn Intellisense and my eyes;-) Could have sworn it looked like a delegate. I should have second guessed myself when i found it in System.Collections...thanks
JoshBerke
+8  A: 

You even got the names right :)

See System.Comparison<T>

Joel Coehoorn
Lol. Y'know I thought I looked for that. Oh well.
Neil Barnwell
A: 

Why not just use Func?

void Example<T>(Func<T,T,int> comparereDel) {
  ...
}
JaredPar