Map.TryFind<'Key,'Value>-Methode (F#)

Aktualisiert: August 2010

Sucht ein Element in der Zuordnung und gibt einen Some-Wert zurück, wenn das Element in der Domäne der Zuordnung vorhanden ist, oder None, wenn es nicht vorhanden ist.

Namespace/Modulpfad: Microsoft.FSharp.Collections

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

// Signature:
member this.TryFind : 'Key -> 'Value option (requires comparison)

// Usage:
map.TryFind (key)

Parameter

  • key
    Typ: 'Key

    Der Eingabeschlüssel.

Rückgabewert

Der zugeordnete Wert oder None, wenn der Schlüssel nicht in der Zuordnung enthalten ist.

Beispiel

Im folgenden Beispiel wird die Verwendung der TryFind-Methode veranschaulicht.

let map1 = [ for i in 1 .. 100 -> (i, i*i) ] |> Map.ofList
let result = map1.TryFind 50
match result with
| Some x -> printfn "Found %d." x
| None -> printfn "Did not find the specified value."

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

Microsoft.FSharp.Collections-Namespace (F#)

Änderungsprotokoll

Datum

Versionsgeschichte

Grund

August 2010

Codebeispiel hinzugefügt.

Informationsergänzung.