title: Prevent dictionary from modifications
body: <p>How do I prevent dictionary items from modification outside of my class?
  I have to expose collection of objects as a property, but then everyone can do everything with my objects. I tried to use <code>ReadOnlyDictionary</code> to wrap my public property, but <code>IntegerValue</code> property still can be modified from outside.</p>
  
  <p>Sample code is below:</p>
  
  <pre><code>internal class MyRefClass
  {
      public object ReferenceStrig;
      public int IntegerValue;
  
      public MyRefClass()
      {
       ReferenceStrig = "Initialized string";
          IntegerValue = 100;
      }
  }
  
  class Program
  {
      static void Main(string[] args)
      {
          var writableDict = new Dictionary&lt;int, MyRefClass&gt;();
          writableDict.Add(1,new MyRefClass());
  
          ReadOnlyDictionary&lt;int, MyRefClass&gt; dict = new ReadOnlyDictionary&lt;int, MyRefClass&gt;(writableDict);
  
      MyRefClass variable;
      dict.TryGetValue(1, out variable); #get an object from dictionary
      variable.IntegerValue = 0; #changing property of the object
  
      writableDict.TryGetValue(1, out variable); #get the same object once again
      #now property variable.IntegerValue == 0 instead of 100!
      }
  }
  </code></pre>