JetBrains Rider 2023.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, 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); }
Last modified: 13 December 2023