次の方法で共有


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

マップ内の要素を検索します。マップ内に束縛が存在しない場合は KeyNotFoundException を発生させます。

名前空間/モジュール パス: Microsoft.FSharp.Collections.Map

アセンブリ: FSharp.Core (FSharp.Core.dll)

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

// Usage:
Map.find key table

パラメーター

  • key
    型: 'Key

    入力キー。

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

    入力マップ。

例外

例外

状態

KeyNotFoundException

マップ内にキーが存在しない場合にスローされます。

戻り値

指定したキーに割り当てられている値。

解説

この関数は、コンパイルされたアセンブリでは Find という名前です。F# 以外の言語から、またはリフレクションを使用してこの関数にアクセスする場合は、この名前を使用します。

使用例

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

出力

  
  
  
  
  

プラットフォーム

Windows 8、Windows 7、Windows Server 2012 で Windows Server 2008 R2

バージョン情報

F# コア ライブラリのバージョン

サポート: ポータブル 2.0、4.0

参照

関連項目

Collections.Map モジュール (F#)

Microsoft.FSharp.Collections 名前空間 (F#)