Is it possible with C# to pass a lambda expression as an IComparer argument in a method call?
eg something like
var x = someIEnumerable.OrderBy(aClas
As Jeppe points out, if you're on .NET 4.5, you can use the static method Comparer.
If not, this is an implementation that should be equivalent:
public class FunctionalComparer : IComparer
{
private Func comparer;
public FunctionalComparer(Func comparer)
{
this.comparer = comparer;
}
public static IComparer Create(Func comparer)
{
return new FunctionalComparer(comparer);
}
public int Compare(T x, T y)
{
return comparer(x, y);
}
}