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

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

Den Delimarsky|Last Updated: 7/18/2016
|
1 Contributor

Tests if an element is in the domain of the map.

Namespace/Module Path: Microsoft.FSharp.Collections

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

Syntax

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

// Usage:
map.ContainsKey (key)

Parameters

key Type: 'Key

The input key.

Return Value

true if the map contains the given key.

Example


    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

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

Microsoft.FSharp.Collections Namespace (F#)

© 2016 Microsoft