title: const Dictionary in c#
body: <p>I have a class in C# that contains a Dictionary, which I want to create and ensure nothing as added, edited or removed from this dictionary as long as the class which contains it exists.</p>
  
  <p>readonly doesn't really help, once I tested and saw that I can add items after. Just for instance, I created an example:</p>
  
  <pre><code>public class DictContainer
  {
      private readonly Dictionary&lt;int, int&gt; myDictionary;
  
      public DictContainer()
      {
          myDictionary = GetDictionary();
      }
  
      private Dictionary&lt;int, int&gt; GetDictionary()
      {
          Dictionary&lt;int, int&gt; myDictionary = new Dictionary&lt;int, int&gt;();
  
          myDictionary.Add(1, 2);
          myDictionary.Add(2, 4);
          myDictionary.Add(3, 6);
  
          return myDictionary;
      }
  
      public void Add(int key, int value)
      {
          myDictionary.Add(key, value);
      }
  
  }
  </code></pre>
  
  <p>I want the Add method not to work. If possible, I want it not to even compile. Any suggestions?</p>
  
  <p>Actually, I'm worried for it is code that will be open for a lot of people to change. So, even if I hide the Add method, it will be possible for someone to "innocently" create a method which add a key, or remove another. I want people to look and know they shouldn't change the dictionary in any ways. Just like I have with a const variable.</p>