łatwy sposób get jeden klucz:
public static TKey GetKey<TKey,TValue>(Dictionary<TKey, TValue> dictionary, TValue Value)
{
List<TKey> KeyList = new List<TKey>(dictionary.Keys);
foreach (TKey key in KeyList)
if (dictionary[key].Equals(Value))
return key;
throw new KeyNotFoundException();
}
i wielokrotność klawiszy:
public static TKey[] GetKeys<TKey, TValue>(Dictionary<TKey, TValue> dictionary, TValue Value)
{
List<TKey> KeyList = new List<TKey>(dictionary.Keys);
List<TKey> FoundKeys = new List<TKey>();
foreach (TKey key in KeyList)
if (dictionary[key].Equals(Value))
FoundKeys.Add(key);
if (FoundKeys.Count > 0)
return FoundKeys.ToArray();
throw new KeyNotFoundException();
}
możliwy duplikat [Uzyskiwanie klucza wartości ogólnego słownika?] (Http://stackoverflow.com/questions/255341/getting-key-of-value-of-a-generic-dictionary) – bluish