确实,那根本不会有效。
您总是可以编写扩展方法:
public static TValue GetValueOrDefault<TKey,TValue> (this IDictionary<TKey, TValue> dictionary, TKey key){ TValue ret; // Ignore return value dictionary.TryGetValue(key, out ret); return ret;}或使用C#7.1:
public static TValue GetValueOrDefault<TKey,TValue> (this IDictionary<TKey, TValue> dictionary, TKey key) => dictionary.TryGetValue(key, out var ret) ? ret : default;
使用:
- 表示形式的方法(C#6)
- 输出变量(C#7.0)
- 默认文字(C#7.1)



