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

Cerca un elemento nella mappa.Genera KeyNotFoundException se non esiste alcuna associazione nella mappa.

Percorso spazio dei nomi/modulo: 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

Parametri

  • key
    Tipo: 'Key

    Chiave di input.

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

    Mappa di input.

Eccezioni

Eccezione

Condizione

KeyNotFoundException

Generata se la chiave non esiste nella mappa.

Valore restituito

Valore mappato alla chiave specificata.

Note

Questa funzione è denominata Find negli assembly compilati.Utilizzare questo nome se si accede alla funzione da un linguaggio diverso da F# o tramite reflection.

Esempio

Negli esempi riportati di seguito viene illustrato l'utilizzo di 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

Output

  
  
  
  
  

Piattaforme

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

Informazioni sulla versione

Versioni della libreria di base F#

Supportato in: 2,0, 4,0, portabile

Vedere anche

Riferimenti

Modulo Collections.Map (F#)

Spazio dei nomi Microsoft.FSharp.Collections (F#)