title: Creating a constant Dictionary in C#
body: <p>What is the most efficient way to create a <strong>constant</strong> (never changes at runtime) mapping of <code>string</code>s to <code>int</code>s? </p>
  
  <p>I've tried using a <a href="https://stackoverflow.com/questions/268064/c-how-can-dictionarykv-implement-icollectionkeyvaluepairkv-without-having-addke">const Dictionary</a>, but that didn't work out. </p>
  
  <p>I could implement a <a href="https://stackoverflow.com/questions/35002/does-c-have-a-way-of-giving-me-an-immutable-dictionary">immutable wrapper</a> with appropriate semantics, but that still doesn't seem totally right.</p>
  
  <hr>
  
  <p>For those who have asked, I'm implementing <a href="https://msdn.microsoft.com/en-us/library/system.componentmodel.idataerrorinfo(v=vs.110).aspx" rel="noreferrer">IDataErrorInfo</a> in a generated class and am looking for a way to make the columnName lookup into my array of descriptors. </p>
  
  <p>I wasn't aware (typo when testing! d'oh!) that switch accepts strings, so that's what I'm gonna use. Thanks!</p>