【发布时间】:2025-12-09 21:25:01
【问题描述】:
有这些基本定义
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 的签名很清楚 - 它只需要一个(字符串)参数。
任何人都可以在这里解释一下吗?
【问题讨论】: