Dictionary looked up twice (CA1854)
Esta página aún no está disponible en tu idioma.
Key dotnet.performance.double-dictionary-lookup · Severity info · Category performance
Microsoft analyzer CA1854. Flags ContainsKey followed by the indexer on the same key - two lookups where TryGetValue does one.
Incorrect
Section titled “Incorrect”if (cache.ContainsKey(key)) return cache[key];Correct
Section titled “Correct”if (cache.TryGetValue(key, out var value)) return value;