I was building a cellular automaton earlier (fireflies simulation) and I decided to use a C# enum to represent a fly's current state (Charging, Sensitive, and Flashing). This is fine.
However when it came to rendering the CA world I needed to map a Color instance to each state, so I created a static Dictionary<FlyState,Color> member whereby a colour could be matched to a fly's state.
However NProf reports that the dictionary's FindEntry call (from the indexer property) was consuming 50% of my program's CPU time (eh wtf).
I modified my code to use Dictionary<Int32,Color> and changed the indexer property call to cast the FlyState to int, and suddenly it dropped from 50% down to 4%.
I'd have thought Dictionary would call .GetHashCode on the enum directly, which (should) be identical to Int32.GetHashCode.
So what's going on, eh?