使用方法组给我 以下方法或属性之间的调用不明确:



我想在 Linq 中调用一个简单的方法组,但我收到此错误。

The call is ambiguous between the following methods or properties: 'System.Linq.Enumerable.Select<string,int>(System.Collections.Generic.IEnumerable<string>, System.Func<string,int>)' and 'System.Linq.Enumerable.Select<string,int>(System.Collections.Generic.IEnumerable<string>, System.Func<string,int,int>)'

var num = new [] { "12345", "5432" };
num.Select(Convert.ToInt32);

我知道调用哪个方法之间存在歧义。但是,我的问题是,有没有办法在不正常调用该方法的情况下指定签名。我想通过不必使用 lambda 表达式来节省键入。

谢谢。

你可以显式投射:

num.Select((Func<String, Int32>)Convert.ToInt32);

最新更新