「C#」ContainsKeyでDictionaryのキーがあるかを取得
書式
public bool ContainsKey (TKey key);
指定したキーを持つ要素が true に格納されている場合は Dictionary<TKey,TValue>。
それ以外の場合は false。
使用例
using System;
using System.Collections.Generic;
class Arkgame
{
    public static void Main()
    {
        //Dictionaryクラスをインスタンス
        var citys = new Dictionary<int, string>();
        citys.Add(101, "東京");
        citys.Add(202, "大阪");
        citys.Add(303, "福岡");
        var str = 202;
        //指定のキーがあるか真偽値を返す
        if (citys.ContainsKey(str))
        {
            Console.WriteLine("指定のキー" + str + "が存在します");
        }
        Console.ReadKey();
    }
}
実行結果
指定のキー202が存在します