当使用 lambda 表达式从以下代码中查找最大键值时,在使用 gmcs 在 Unix 系统上编译时出现以下编译错误:
List<KeyValuePair<int, RunnerBase>> lsFinishOrder = new List<KeyValuePair<int, RunnerBase>>();
...fill out List...
iMaxPlace = lsFinishOrder.Max(p => p.Key);
代码在 Windows 机器上编译良好,并在执行时按预期执行,只有当我尝试在 Linux 上编译它时才会出现问题。
error CS0121: The call is ambiguous between the following methods or properties: `System.Linq.Enumerable.Max<System.Collections.Generic.KeyValuePair<int,Pathfinder.RunnerBase>>(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<int,Pathfinder.RunnerBase>>, System.Func<System.Collections.Generic.KeyValuePair<int,Pathfinder.RunnerBase>, long >)'
and `System.Linq.Enumerable.Max<System.Collections.Generic.KeyValuePair<int,Pathfinder.RunnerBase>>(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<int,Pathfinder.RunnerBase>>, System.Func<System.Collections.Generic.KeyValuePair<int,Pathfinder.RunnerBase>, int >)'
/usr/lib/mono/gac/System.Core/3.5.0.0__b77a5c561934e089/System.Core.dll (Location of the symbol related to previous error)
任何想法都将受到欢迎,因为我已经尝试了很多不同的方法,我想知道我是否没有找错地方。我的 Windows 构建目标是 .Net 3.5。
最佳答案
这看起来像是 Mono 编译器中的错误。
试试这个来帮助它:
iMaxPlace = lsFinishOrder.Max((Func<KeyValuePair<int, RunnerBase>, int>)(p => p.Key));
关于c# - System.Linq.Enumerable.Max 的 Mono 之间的模糊调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24289652/