Determines whether the List(T) contains elements that match the conditions defined by the specified predicate.
Assembly: mscorlib (in mscorlib.dll)
match is a null reference (Nothing in Visual Basic).
The Predicate(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(T) are individually passed to the Predicate(T) delegate, and processing is stopped when a match is found.
This method performs a linear search; therefore, this method is an O(n) operation, where n is Count.
The following code example demonstrates the method and several other methods that use the Predicate(T) generic delegate.
A List(T) of strings is created, containing 8 dinosaur names, two of which (at positions 1 and 5) end with "saurus". The code example also defines a search predicate method named EndsWithSaurus, which accepts a string parameter and returns a Boolean value indicating whether the input string ends in "saurus".
Finally, the method is called. It traverses the list from the beginning, passing each element in turn to the EndsWithSaurus method. The search stops and the method returns true if the EndsWithSaurus method returns true for any element. The method returns false because all such elements have been removed.
In C# and Visual Basic, it is not necessary to create the Predicate<string> delegate (Predicate(Of String) in Visual Basic) explicitly. These languages infer the correct delegate from context and create it automatically.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.