title: dictionary enum key performance
body: <p>I have a concern about generic dictionaries using enums for keys. </p>
  
  <p>As stated at the below page, using enums for keys will allocate memory:
  <a href="https://web.archive.org/web/20190216001802/https://blogs.msdn.microsoft.com/shawnhar/2007/07/02/twin-paths-to-garbage-collector-nirvana/" rel="nofollow noreferrer">http://blogs.msdn.com/b/shawnhar/archive/2007/07/02/twin-paths-to-garbage-collector-nirvana.aspx</a></p>
  
  <p>I've tested and confirmed the behavior, and it's causing problems in my project. For readability, I believe using enums for keys is very useful, and the optimal solution for me would be to write write a class implementing <code>IDictionary&lt;TKey, TValue&gt;</code>, which would use integers for keys internally. The reason is I don't want to change all my existing dictionaries to use integers for keys, and do implicit casting. This would be best performance wise, but it will give me lot of work initially and it will reduce the readability.</p>
  
  <p>So I've tried a couple of approaches, including using <code>GetHashCode</code> (which unfortunately allocates memory) to build an internal <code>Dictionary&lt;int, TValue&gt;</code>.</p>
  
  <p>So, to wrap it up in one question; can anyone think of a solution that I can use to keep the readability of <code>Dictionary&lt;SomeEnum, TValue&gt;</code>, while having the perfomance of a <code>Dictionary&lt;int, TValue&gt;</code>?</p>
  
  <p>Any advice much appreciated. </p>