List<(Of <(T>)>).FindAll Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Retrieves all the elements that match the conditions defined by the specified predicate.
Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll)
Syntax
Public Function FindAll ( _
match As Predicate(Of T) _
) As List(Of T)
public List<T> FindAll(
Predicate<T> match
)
Parameters
- match
Type: System..::.Predicate<(Of <(T>)>)
The Predicate<(Of <(T>)>) delegate that defines the conditions of the elements to search for.
Return Value
Type: System.Collections.Generic..::.List<(Of <(T>)>)
A List<(Of <(T>)>) containing all the elements that match the conditions defined by the specified predicate, if found; otherwise, an empty List<(Of <(T>)>).
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | match is nullNothingnullptra null reference (Nothing in Visual Basic). |
Remarks
The Predicate<(Of <(T>)>) is a delegate to a method that returns true if the object passed to it matches the conditions defined in the delegate. The elements of the current List<(Of <(T>)>) are individually passed to the Predicate<(Of <(T>)>) delegate, and the elements that match the conditions are saved in the returned List<(Of <(T>)>).
This method performs a linear search; therefore, this method is an O(n) operation, where n is Count.
Examples
The following example demonstrates the find methods for the List<(Of <(T>)>) class. The example for the List<(Of <(T>)>) class contains book objects, of class Book, using the data from the Sample XML File: Books (LINQ to XML). The FillList method in the example uses LINQ to XML to parse the values from the XML to property values of the book objects.
The following table describes the examples provided for the find methods.
Method |
Example |
---|---|
Finds a book by an ID using the IDToFind predicate delegate. C# example uses an anonymous delegate. |
|
FindAll(Predicate<(Of <(T>)>)) |
Find all books that whose Genre property is "Computer" using the FindComputer predicate delegate. |
Finds the last book in the collection that has a publish date before 2001, using the PubBefore2001 predicate delegate. C# example uses an anonymous delegate. |
|
Finds the index of first computer book using the FindComputer predicate delegate. |
|
Finds the index of the last computer book using the FindComputer predicate delegate. |
|
Finds the index of first computer book in the second half of the collection, using the FindComputer predicate delegate. |
|
Finds the index of last computer book in the second half of the collection, using the FindComputer predicate delegate. |
Version Information
Windows Phone OS
Supported in: 8.1, 8.0