「C#」ContainsValueでDictionaryの特定の値があるか真偽値を返す
構文
public bool ContainsValue (TValue value);
指定した値を持つ要素が 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 = "大阪";
        //指定の値があるか真偽値を返す
        if (citys.ContainsValue(str))
        {
            Console.WriteLine("指定の値「" + str + "」が存在します");
        }
        Console.ReadKey();
    }
}
実行結果
指定の値「大阪」が存在します