ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

Code inspection: Dictionary item removal can be simplified with single 'Remove'

Last modified: 23 July 2024

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.