Partager via


Map.find<'Key,'T>, fonction (F#)

Recherche un élément dans le mappage. En l'absence de liaison dans le mappage, lève KeyNotFoundException.

Espace de noms/Chemin du module : Microsoft.FSharp.Collections.Map

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

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

// Usage:
Map.find key table

Paramètres

  • key
    Type : 'Key

    Touche de saisie.

  • table
    Type : Map<'Key,'T>

    Mappage d'entrée.

Exceptions

Exception

Condition

KeyNotFoundException

Levée lorsque la clé n'existe pas dans le mappage.

Valeur de retour

Valeur mappée à la clé donnée.

Notes

Cette fonction se nomme Find dans les assemblys compilés. Si vous accédez à la fonction à partir d'un langage autre que F# ou par réflexion, utilisez ce nom.

Exemple

Les exemples suivants montrent comment utiliser Map.filter.

let findAndPrint key map =
    printfn "With key %d, found value %A." key (Map.find key map)
let map1 = Map.ofList [ (1, "one"); (2, "two"); (3, "three") ]
let map2 = Map.ofList [ for i in 1 .. 10 -> (i, i*i) ]
try
    findAndPrint 1 map1
    findAndPrint 2 map1
    findAndPrint 3 map2
    findAndPrint 5 map2
    // The key is not in the map, so this throws an exception.
    findAndPrint 0 map2
with
     :? System.Collections.Generic.KeyNotFoundException as e -> printfn "%s" e.Message

Sortie

            

Plateformes

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

Informations de version

Runtime F#

Pris en charge dans : 2.0, 4.0

Silverlight

Prise en charge dans : 3

Voir aussi

Référence

Collections.Map, module (F#)

Microsoft.FSharp.Collections, espace de noms (F#)