I'm trying to sort part of a list with a lambda expression, but I get an error when trying to do so:
List<int> list = new List<int>();
list.Add(1);
list.Add(3);
list.Add(2);
list.Add(4);
// works fine
list.Sort((i1, i2) => i1.CompareTo(i2) );
// "Cannot convert lambda expression to type 'System.Collections.Generic.IComparer<int>' because it is not a delegate type"
list.Sort(1, 2, (i1, i2) => i1.CompareTo(i2) );
foreach (int i in list)
Console.WriteLine(i);
At a guess this is because there's no System.Comparison overload for the sort that takes a range. Is this omitted for any particular reason?
Is there an easy way of getting a suitable IComparer from the lambda expression (like a class I can just use to go list.Sort(1, 2, new CompareyThing<int>((...) => ...))
or something)?