这只是一个好奇的问题,我想知道是否有人有一个好的答案:
在 .NET Framework 类库中,我们有以下两个方法:
public static IQueryable<TSource> Where<TSource>(
this IQueryable<TSource> source,
Expression<Func<TSource, bool>> predicate
)
public static IEnumerable<TSource> Where<TSource>(
this IEnumerable<TSource> source,
Func<TSource, bool> predicate
)
他们为什么使用Func<TSource, bool>
代替Predicate<TSource>
?似乎是Predicate<TSource>
仅由以下人员使用List<T>
and Array<T>
, while Func<TSource, bool>
几乎所有人都使用Queryable
and Enumerable
方法和扩展方法...这是怎么回事?
While Predicate
已同时推出List<T>
and Array<T>
,在.net 2.0中,不同的Func
and Action
变体来自.net 3.5。
所以那些Func
谓词主要用于 LINQ 运算符中的一致性。从 .net 3.5 开始,关于使用Func<T>
and Action<T>
the 指导方针国家:
请使用新的 LINQ 类型Func<>
and
Expression<>
而不是定制
委托和谓词
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)