title: Returning a dictionary in c# in a multi-threaded environment
body: <p>I have declared a dictionary of dicionary:</p>
  
  <pre><code>Dictionary&lt;String, Dictionary&lt;String, String&gt;&gt; values;
  </code></pre>
  
  <p>I have a getter to get a dictionary at a specific index:</p>
  
  <pre><code>public Dictionary&lt;String,String&gt; get(String idx)
  {
      lock (_lock)
      {
          return values[moduleName];
      }
  }
  </code></pre>
  
  <p>As you can see I am working in a multi-threaded environment.
  My question is do I need to return a copy of my dictionary in order to be thread safe like this:</p>
  
  <pre><code>public Dictionary&lt;String,String&gt; get(String idx)
  {
      lock (_lock)
      {
          return new Dictionary&lt;string, string&gt;(values[moduleName]);
      }
  }
  </code></pre>
  
  <p>If I don't will the class that calls the getter receive a copy (so if I remove this dictionary from my <code>Dictionary&lt;String, Dictionary&lt;String, String&gt;&gt;</code> will it still work)?</p>
  
  <p>Cheers,</p>
  
  <p>Thierry.</p>