All rules
CA1853Performance Enabled by default: As suggestion

Unnecessary call to 'Dictionary.ContainsKey(key)'

Unnecessary call to 'Dictionary.ContainsKey(key)'

Microsoft docs

Description

There's no need to guard Dictionary.Remove(key) with Dictionary.ContainsKey(key). System.Collections.Generic.Dictionary2.Remove(0) already checks whether the key exists and doesn't throw if it doesn't exist.

Cause

A call to System.Collections.Generic.Dictionary2.Remove(0) is guarded with a call to System.Collections.Generic.Dictionary2.ContainsKey(0).

How to fix violations

Remove the guarding code that calls System.Collections.Generic.Dictionary2.ContainsKey(0).

Example

Dictionary<string, int> d = new();
if (d.ContainsKey("name"))
    d.Remove("name");

Dictionary<string, int> d = new();
d.Remove("name");

When to suppress

It's safe to suppress a warning if performance isn't a concern.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0