共用方式為


List.exists2<'T1,'T2> 函式 (F#)

更新:2010 年 5 月

測試清單中是否有任何對應項目配對滿足指定的述詞。

命名空間/模組路徑: Microsoft.FSharp.Collections.List

組件:FSharp.Core (在 FSharp.Core.dll 中)

// Signature:
List.exists2 : ('T1 -> 'T2 -> bool) -> 'T1 list -> 'T2 list -> bool

// Usage:
List.exists2 predicate list1 list2

參數

  • predicate
    Type: 'T1 -> 'T2 -> bool

    用來測試輸入項目的函式。

  • list1
    Type: 'T1 list

    第一個輸入清單。

  • list2
    Type: 'T2 list

    第二個輸入清單。

傳回值

true如果任何對項目滿足述詞。 否則會傳回 false。

備註

這個述詞套用至兩個集合中符合的項目,數目最多可達長度較短之集合的長度。 如果有任何應用程式傳回 true,則整體結果為 true,而且不會測試之後的任何項目。

這個函式是名為 Exists2中 已編譯的組件。 如果從以.NET 語言,F # 以外,或透過反映存取函式使用這個名稱。

範例

下列程式碼範例說明如何使用 List.exists2

// Use List.exists2 to compare elements in two lists.
// isEqualElement returns true if any elements at the same position in two supplied
// lists match.
let isEqualElement list1 list2 = List.exists2 (fun elem1 elem2 -> elem1 = elem2) list1 list2
let list1to5 = [ 1 .. 5 ]
let list5to1 = [ 5 .. -1 .. 1 ]
if (isEqualElement list1to5 list5to1) then
    printfn "Lists %A and %A have at least one equal element at the same position." list1to5 list5to1
else
    printfn "Lists %A and %A do not have an equal element at the same position." list1to5 list5to1

輸出

  

平台

Windows 7、Windows Vista SP2、Windows XP SP3、Windows XP x64 SP2、Windows Server 2008 R2、Windows Server 2008 SP2、Windows Server 2003 SP2

版本資訊

F# 執行階段

支援版本:2.0、4.0

Silverlight

支援版本:3

請參閱

參考

Collections.List 模組 (F#)

Microsoft.FSharp.Collections 命名空間 (F#)

變更記錄

日期

History

原因

2010 年 5 月

加入程式碼範例。

資訊加強。