You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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<int, object[]> a = [];
// ... population of "a" from other code ...
if (a.ContainsKey(seed))
{
a.Remove(seed);
Dictionary<int, object[]> a2 = [a];
// alternatively: Dictionary<int, object[]> 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[])
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:
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
Related Issues
The text was updated successfully, but these errors were encountered: