Contract::ForAll<T> Method (IEnumerable<T>^, Predicate<T>^)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Determines whether all the elements in a collection exist within a function.

Namespace:   System.Diagnostics.Contracts
Assembly:  mscorlib (in mscorlib.dll)

generic<typename T>
static bool ForAll(
	IEnumerable<T>^ collection,
	Predicate<T>^ predicate


Type: System.Collections.Generic::IEnumerable<T>^

The collection from which elements of type T will be drawn to pass to predicate.

Type: System::Predicate<T>^

The function to evaluate for the existence of all the elements in collection.

Return Value

Type: System::Boolean

true if and only if predicate returns true for all elements of type T in collection.

Type Parameters


The type that is contained in collection.

Exception Condition

collection or predicate is null.

The following example demonstrates how to use the ForAll<T> method to determine whether a collection has a null element.

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

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Available since 4.0
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top