Using ContainsKey() followed by an indexer on dictionaries results in a double lookup, decreasing performance. This is common anti-pattern. This article will show you how to fix this and increase performance up to 2x.
Tag: CA1854
256 Seconds with dotNetDave: Be careful using ContainsKey() with Dictionary Types
In this episode, I will demonstrate the issues associated with using `ContainsKey()` with Dictionary types in Microsoft .NET, which can potentially lead to performance problems. Updated September 2023.

You must be logged in to post a comment.