'Passing Delegate to Sort()
In the book "Functional C#" by Enrico Buonanno, on page 16, the following Code was given:
namespace System
{
public delegate int Comparison<in T>(T x, T y);
}
var list = Enumerable.Range(1, 10).Select(i => i * 3).ToList();
list // => [3, 6, 9, 12, 15, 18, 21, 24, 27, 30]
Comparison<int> alphabetically = (l, r)
=> l.ToString().CompareTo(r.ToString());
list.Sort(alphabetically);
list // => [12, 15, 18, 21, 24, 27, 3, 30, 6, 9]
This, however, when executed in the REPL, doesn't yield anything useful.
error CS1503: Argument "1": Konvertierung von "Comparison<int>" in "System.Collections.Generic.IComparer<int>" nicht möglich.
What's going wrong?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
