Code inspection: Dictionary item removal can be simplified with single 'Remove'Last modified: 08 April 2024 Category: Common Practices and Code Improvements ID: CanSimplifyDictionaryRemovingWithSingleCall EditorConfig: resharper_can_simplify_dictionary_removing_with_single_call_highlighting Default severity: Suggestion Language: C# Requires SWA: NotipYou can suppress this inspection to ignore specific issues, change its severity level to make the issues less or more noticeable, or disable it altogether.The Remove method in Dictionary<T, T> in C# does not throw an exception if the key is not found, it simply returns false. This means you do not need to use TryGetValue to check if the key exists in the dictionary before trying to remove it.Suboptimal codeint RemoveValue(Dictionary<int, int> d, int toRemove){ if (d.TryGetValue(toRemove, out var result)) { d.Remove(toRemove); return result; } return -1;}After the quick-fixint RemoveValue(Dictionary<int, int> d, int toRemove){ if (d.Remove(toRemove, out var result)) { return result; } return -1;}