The Sort
method takes a delegate called Comparison<T>
. You're trying to pass in a Func<int, int, bool>
, which is itself a delegate. There is no conversion between the delegate Func<int, int, bool>
and the delegate Comparison<T>
.
You can, however, use a lambda expression.
items.Sort((a, b) => a.DateModified.CompareTo(b.DateModified));
Indeed, you use this very lambda expression and pass it into the Func<int, int, bool>
constructor*. However, there is no need. A lambda expression can be converted into any delegate whos signature matches - that is (a, b) => a.DateModified.CompareTo(b.DateModified)
can be assigned to something typed Func<int, int, int>
or something typed Comparison<T>
. In this case we pass it in to something which expects a Comparison<T>
.
*
With one minor adjustment. Sort expectes an integer as a return type. Negative values indicate less than, 0 indicates equal, and positive values indicate greater than.