title: ContainsKey Thread Safe
body: <p>In the following code:</p>
  
  <pre><code>public class StringCache
  {
      private readonly object lockobj = new object();
  
      private readonly Dictionary&lt;int, string&gt; cache = new Dictionary&lt;int, string&gt;();
  
      public string GetMemberInfo(int key)
      {
          if (cache.ContainsKey(key))
              return cache[key];
          lock (lockobj)
          {
              if (!cache.ContainsKey(key))
                  cache[key] = GetString(key);
          }
          return cache[key];
      }
  
      private static string GetString(int key)
      {
          return "Not Important";
      }
  }
  </code></pre>
  
  <p>1) Is ContainsKey thread safe?  IOW, what happens if that method is executing when another thread is adding something to the dictionary?
  2) For the first return cache[key], is there any chance that it could return a garbled value?  </p>
  
  <p>TIA,</p>
  
  <p>MB</p>