how to access a dictionary item by key, if the key is
List<string>? I apologize for the incomplete description. I need not just get the value, but increase it by 1.
how to access a dictionary item by key, if the key is
List<string>? I apologize for the incomplete description. I need not just get the value, but increase it by 1.
KeyNotFoundException try { Console.WriteLine("Значение = {0}.", dict[key]); } catch (KeyNotFoundException) { Console.WriteLine("Ключ не найден."); } Dictionary<TKey, TValue>.TryGetValue (TKey, TValue) method Dictionary<TKey, TValue>.TryGetValue (TKey, TValue) if (dict.TryGetValue(key, out value)) { Console.WriteLine("Значение = {0}.", value); } else { Console.WriteLine("Ключ не найден."); } if (dict.ContainsKey(key)) { Console.WriteLine("Значение = {0}.", dict[key]); } else { Console.WriteLine("Ключ не найден."); } Use the Dictionary.TryGetValue() method
var myValue; List<string> key; if (MyDict.TryGetValue(key, out myValue)) { /* use myValue */ } Source: https://ru.stackoverflow.com/questions/646537/
All Articles
List<T>should not be used as a hash table key - it does not have GetHashCode redefined. - kmv