JetBrains Rider 2025.1 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, JetBrains Rider 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); }
04 June 2024