Contract.Exists Method

Definition

Overloads

Exists(Int32, Int32, Predicate<Int32>)

Determines whether a specified test is true for any integer within a range of integers.

Exists<T>(IEnumerable<T>, Predicate<T>)

Determines whether an element within a collection of elements exists within a function.

Exists(Int32, Int32, Predicate<Int32>)

Source:
Contracts.cs
Source:
Contracts.cs
Source:
Contracts.cs

Determines whether a specified test is true for any integer within a range of integers.

C#
public static bool Exists(int fromInclusive, int toExclusive, Predicate<int> predicate);

Parameters

fromInclusive
Int32

The first integer to pass to predicate.

toExclusive
Int32

One more than the last integer to pass to predicate.

predicate
Predicate<Int32>

The function to evaluate for any value of the integer in the specified range.

Returns

true if predicate returns true for any integer starting from fromInclusive to toExclusive - 1.

Exceptions

predicate is null.

toExclusive is less than fromInclusive.

Remarks

The toExclusive parameter is one more than the last integer to facilitate using the length of a range of integers starting at 0. For example, it would be set to 5 for integers 0 through 4.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

Exists<T>(IEnumerable<T>, Predicate<T>)

Source:
Contracts.cs
Source:
Contracts.cs
Source:
Contracts.cs

Determines whether an element within a collection of elements exists within a function.

C#
public static bool Exists<T>(System.Collections.Generic.IEnumerable<T> collection, Predicate<T> predicate);

Type Parameters

T

The type that is contained in collection.

Parameters

collection
IEnumerable<T>

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

predicate
Predicate<T>

The function to evaluate for an element in collection.

Returns

true if and only if predicate returns true for any element of type T in collection.

Exceptions

collection or predicate is null.

See also

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0