LINQ,其中()VS的FindAll() [英] LINQ, Where() vs FindAll()
问题描述
有人能解释如何LINQ的功能在哪里(..)和的FindAll(..)有什么区别?他们似乎都做同样的事情...
Can someone explain how the LINQ functions Where(..) and FindAll(..) differ? They both seem to do the same thing...
推荐答案
的FindAll()
是一个函数列表< T>
类型,它不是像其中,
。 LINQ的扩展方法在任何类型的工作,实现的IEnumerable
,而的FindAll
只能在列表< T>
实例(或继承它,当然,类的实例)
FindAll()
is a function on the List<T>
type, it's not a LINQ extension method like Where
. The LINQ extension methods work on any type that implements IEnumerable
, whereas FindAll
can only be used on List<T>
instances (or instances of classes that inherit from it, of course).
此外,它们在实际目的不同。 其中,
返回即当对象被列举的按需执行的IEnumerable
的一个实例。 的FindAll
返回一个新的列表&LT; T&GT;
包含请求的元素。 的FindAll
更像是调用其中,(...)。了ToList()
上的一个实例的IEnumerable
。
Additionally, they differ in actual purpose. Where
returns an instance of IEnumerable
that is executed on-demand when the object is enumerated. FindAll
returns a new List<T>
that contains the requested elements. FindAll
is more like calling Where(...).ToList()
on an instance of IEnumerable
.
这篇关于LINQ,其中()VS的FindAll()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!