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

Sucht ein Element in der Zuordnung. Löst KeyNotFoundException aus, wenn in der Zuordnung keine Bindung vorhanden ist.

Namespace/Modulpfad: 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

Parameter

  • key
    Typ: 'Key

    Der Eingabeschlüssel.

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

    Die Eingabezuordnung.

Ausnahmen

Ausnahme

Bedingung

KeyNotFoundException

Wird ausgelöst, wenn der Schlüssel in der Zuordnung nicht vorhanden ist.

Rückgabewert

Der dem angegebenen Schlüssel zugeordnete Wert.

Hinweise

Der Name dieser Funktion in kompilierten Assemblys lautet Find. Verwenden Sie diesen Namen, wenn Sie in einer anderen .NET-Sprache als F# oder durch Reflektion auf die Funktion zugreifen.

Beispiel

Die folgenden Beispiele veranschaulicht die Verwendung von 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

            

Plattformen

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

Versionsinformationen

F#-Runtime

Unterstützt in: 2.0, 4.0

Silverlight

Unterstützt in: 3

Siehe auch

Weitere Ressourcen

Collections.Map-Modul (F#)

Microsoft.FSharp.Collections-Namespace (F#)