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
    类型:'T1 -> 'T2 -> bool

    要测试输入元素的函数。

  • list1
    类型:'T1 list

    第一个输入列表。

  • list2
    类型:'T2 list

    第二个输入列表。

返回值

如果有任何元素对满足谓词,则为true。 否则,返回 false。

备注

谓词将应用于两个集合中接近于集合的两个长度中的较小者的匹配元素。 如果任何应用程序返回 true,则总体结果为 true,并且不再测试其他元素。

此函数在编译的程序集中名为 Exists2。 如果从 F# 以外的 .NET 语言中访问函数,或通过反射访问成员,请使用此名称。

示例

下面的代码示例演示 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

Output

  

平台

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

修订记录

Date

修订记录

原因

2010 年 5 月

添加了代码示例。

信息补充。