# Contract.Exists 方法

## 多載

 Exists(Int32, Int32, Predicate) 判斷整數範圍內是否有任何整數使指定的測試成立。Determines whether a specified test is true for any integer within a range of integers. Exists(IEnumerable, Predicate) 判斷項目集合內的項目是否出現在函式中。Determines whether an element within a collection of elements exists within a function.

## Exists(Int32, Int32, Predicate<Int32>)

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

toExclusive
Int32

predicate
Predicate<Int32>

#### 例外狀況

`predicate``null``predicate` is `null`.

`toExclusive` 小於 `fromInclusive``toExclusive` 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>)

``````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
IEnumerable<T>

predicate
Predicate<T>

#### 例外狀況

`collection``predicate``null``collection` or `predicate` is `null`.