ContainsKey followed by Add (CA1864)
Key dotnet.performance.containskey-then-add · Severity info · Category performance
Microsoft analyzer CA1864. Flags a ContainsKey guard before Dictionary.Add - TryAdd does both in one lookup.
Incorrect
Section titled “Incorrect”if (!totals.ContainsKey(sku)) totals.Add(sku, 0);Correct
Section titled “Correct”totals.TryAdd(sku, 0);