Contract.Exists 方法

定義

多載

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>)

判斷整數範圍內是否有任何整數使指定的測試成立。Determines whether a specified test is true for any integer within a range of integers.

public:
 static bool Exists(int fromInclusive, int toExclusive, Predicate<int> ^ predicate);
public static bool Exists (int fromInclusive, int toExclusive, Predicate<int> predicate);
static member Exists : int * int * Predicate<int> -> bool
Public Shared Function Exists (fromInclusive As Integer, toExclusive As Integer, predicate As Predicate(Of Integer)) As Boolean

參數

fromInclusive
Int32

要傳遞至 predicate 的第一個整數。The first integer to pass to predicate.

toExclusive
Int32

要傳遞至 predicate 的最後一個整數加一。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.

傳回

如果 predicate 為從 fromInclusive 開始到 toExclusive - 1 的任何整數傳回 true,則為 truetrue if predicate returns true for any integer starting from fromInclusive to toExclusive - 1.

例外狀況

predicatenullpredicate is null.

toExclusive 小於 fromInclusivetoExclusive is less than fromInclusive.

備註

toExclusive 參數比最後一個整數還要新,以方便使用從0開始的整數範圍長度。The toExclusive parameter is one more than the last integer to facilitate using the length of a range of integers starting at 0. 例如,整數0到4的會設定為5。For example, it would be set to 5 for integers 0 through 4.

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

判斷項目集合內的項目是否出現在函式中。Determines whether an element within a collection of elements exists within a function.

public:
generic <typename T>
 static bool Exists(System::Collections::Generic::IEnumerable<T> ^ collection, Predicate<T> ^ predicate);
public static bool Exists<T> (System.Collections.Generic.IEnumerable<T> collection, Predicate<T> predicate);
static member Exists : seq<'T> * Predicate<'T> -> bool
Public Shared Function Exists(Of T) (collection As IEnumerable(Of T), predicate As Predicate(Of T)) As Boolean

類型參數

T

包含在 collection 中的型別。The type that is contained in collection.

參數

collection
IEnumerable<T>

將從中取出 T 類型的項目以傳遞至 predicate 的集合。The collection from which elements of type T will be drawn to pass to predicate.

predicate
Predicate<T>

要評估 collection 中項目的函式。The function to evaluate for an element in collection.

傳回

只有在 predicateT 中任何 collection 型別之項目傳回 true 時,才為 truetrue if and only if predicate returns true for any element of type T in collection.

例外狀況

collectionpredicatenullcollection or predicate is null.

另請參閱

適用於