我对泛型很满意,但作为一个喜欢了解每个细节的人,我有这个问题。在我的WhereLINQ 扩展方法的实现中
public static class Extensions
{
public static IEnumerable<T> Where<T>(
this IEnumerable<T> source, Func<T, bool> predicate)
{
foreach (T element in source)
if (predicate(element))
yield return element;
}
}
为什么Tin是Where<T>必要的?为什么不能从Tin推断类型IEnumerable<T>?换句话说,为什么签名不能是
public static IEnumerable<T> Where(this IEnumerable<T> source, Func<T, bool> predicate)
谢谢你的帮助。