using System.Collections.Generic;
public static void Main()
var dicio = new Dictionary<int, string>
Console.WriteLine(dicio.GetByKeyOrDefaullt(65) ?? "Chave inexistente");
Console.WriteLine(dicio.GetByKeyOrDefaullt(80) ?? "Chave inexistente");
Console.WriteLine(dicio.GetByKeyOrDefaullt(69) ?? "Chave inexistente");
public static class DictionaryExtensions
public static TValue GetByKeyOrDefaullt<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key)
=> dict.ContainsKey(key) ? dict[key] : default(TValue);