Map.ContainsKey<'Key,'Value> 方法 (F#)

测试元素是否位于映射的域中。

命名空间/模块路径: Microsoft.FSharp.Collections

程序集:FSharp.Core(在 FSharp.Core.dll 中)

// Signature:
member this.ContainsKey : 'Key -> bool (requires comparison)

// Usage:
map.ContainsKey (key)

参数

  • key
    类型:'Key

    输入键。

返回值

如果映射包含给定键,则为 true。

示例

下面的代码演示如何使用 ContainsKey 方法。

let map1 = Map.ofList [ (1, "one"); (2, "two"); (3, "three") ]
let findKeyAndPrint key (map : Map<int,string>) =
    if (map.ContainsKey key) then
        printfn "The specified map contains the key %d." key
    else
        printfn "The specified map does not contain the key %d." key
findKeyAndPrint 1 map1
findKeyAndPrint 0 map1

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.Map<'Key,'Value> 类 (F#)

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