Table of contents
TOC
Collapse the table of content
Expand the table of content

Map.containsKey<'Key,'T> Function (F#)

Den Delimarsky|Last Updated: 8/18/2017
|
2 Contributors

Evaluates to true if the given key is in the input map.

Namespace/Module Path: Microsoft.FSharp.Collections.Map

Assembly: FSharp.Core (in FSharp.Core.dll)

Syntax

// Signature:
Map.containsKey : 'Key -> Map<'Key,'T> -> bool (requires comparison)

// Usage:
Map.containsKey key table

Parameters

key Type: 'Key

The input key.

table Type: Map<'Key,'T>

The input map.

Return Value

Evaluates to true if the given key is in the input map. Otherwise, it will return false.

Remarks

This function is named ContainsKey in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.

Example


let map1 = Map.ofList [ (1, "one"); (2, "two"); (3, "three") ]
let findKeyAndPrint key map =
    if (Map.containsKey key map) 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

The specified map contains the key 1.
The specified map does not contain the key 0.

Platforms

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Collections.Map Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2018 Microsoft