Additional "When to suppress warnings" should be demonstrated. CA1853 matching is too loose.
- Dominant language
- No language data
- Stars
- 4.8k
- Forks
- 6.1k
- Avg merge
- 19h 10m
- Merged PRs (30d)
- 268
Description
### Type of issue
Incomplete list of reasons to suppress this warning.
### Description
The only item under "When to suppress warnings" is "It's safe to suppress a warning if performance isn't a concern." That's not the only reason.
It's worthwhile to check a Dictionary collection for .ContainsKey() before a .Remove() of that item if we're planning to alter the order of the Dictionary collection by adding the updated item at the end on identical match.
Example:
```
// "seed" is generated as an int earlier
Dictionary a = [];
// ... population of "a" from other code ...
if (a.ContainsKey(seed))
{
a.Remove(seed);
Dictionary a2 = [a];
// alternatively: Dictionary a2 = []; for (int i = 0; i < a.Count; i++) { a2.Add(a.ElementAt(i).Key, a.ElementAt(i).Value); }
a.Clear();
a = a2;
}
a.Add(seed, object[])
```
### Page URL
https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1853
### Content source URL
https://github.com/dotnet/docs/blob/main/docs/fundamentals/code-analysis/quality-rules/ca1853.md
### Document Version Independent Id
e01a0926-70a5-177f-017f-46b93b6c1463
### Article author
@gewarren
### Metadata
* ID: 4fc29d18-6855-2bf4-b53c-856c4cde4499
* Service: **dotnet-fundamentals**
[Related Issues](https://github.com/dotnet/docs/issues?q=is%3Aissue+is%3Aopen+e01a0926-70a5-177f-017f-46b93b6c1463)
Contributor guide
Assessment
This issue has not been assessed yet.