Export (0) Print
Expand All

List(T).TrueForAll Method

Determines whether every element in the List(T) matches the conditions defined by the specified predicate.

Namespace:  System.Collections.Generic
Assembly:  mscorlib (in mscorlib.dll)

member TrueForAll : 
        match:Predicate<'T> -> bool


Type: System.Predicate(T)

The Predicate(T) delegate that defines the conditions to check against the elements.

Return Value

Type: System.Boolean
true if every element in the List(T) matches the conditions defined by the specified predicate; otherwise, false. If the list has no elements, the return value is true.


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 the delegate returns false for any element. The elements are processed in order, and all calls are made on a single thread.

This method is an O(n) operation, where n is Count.

The following example demonstrates the TrueForAll method and several other methods that use 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 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".

The TrueForAll method traverses the list from the beginning, passing each element in turn to the EndsWithSaurus method. The search stops when the EndsWithSaurus method returns false.


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.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft