拥有这些基本定义
我想知道为什么这个代码无法编译:
但是这个可以:
并且。
bool MyFunc(string input)
{
return false;
}
var strings = new[] {"aaa", "123"};
我想知道为什么这个代码无法编译:
var b = strings.Select(MyFunc);
但是这个可以:
var c = strings.Select(elem => MyFunc(elem));
错误信息为"无法从使用中推断方法'System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)'的类型参数。"
Resharper错误提示称它在以下两个类型之间感到困惑:
Select(this IEnumerable<string>, Func<string, TResult>)
并且。
Select(this IEnumerable<string>, Func<string, int, TResult>)
...但是MyFunc的签名很明确——它只需要一个(字符串)参数。
有人能在这里解释一下吗?