ReSharper 2024.3 Help

Code inspection: Dictionary lookup can be simplified with 'GetValueOrDefault'

If you use the Dictionary.TryGetValue() method and fall back to some default value if the key is not found, ReSharper suggest using the dedicated CollectionExtensions.GetValueOrDefault() method instead to improve the structure and readability of your code.

int FindValue(Dictionary<int, int> dic, int index, int fallback) { if (dic.TryGetValue(index, out var v)) return v; return fallback; }
int FindValue(Dictionary<int, int> dic, int index, int fallback) { return dic.GetValueOrDefault(index, fallback); }
Last modified: 04 June 2024