Dictionaries and Enum Keys
Introduction
Enums are a very common type of object used in dictionaries. Unfortunately there is a hidden behavior in dictionaries that use enums as their keys which can cause performance problems - usually resulting from memory allocation.
Our example
Consider the following simple example:
How to fix it
The easiest way to fix this problem is to simply use ints and cast your enums as follows:
This will completely eliminate any allocation that will occur in your ContainsKey call.
Last updated
Was this helpful?