title: Is yield return in C# thread-safe?
body: <p>I have the following piece of code:</p>
  
  <pre><code>private Dictionary&lt;object, object&gt; items = new Dictionary&lt;object, object&gt;;
  public IEnumerable&lt;object&gt; Keys
  {
      get
      {
          foreach (object key in items.Keys)
          {
              yield return key;
          }
      }
  }
  </code></pre>
  
  <p>Is this thread-safe? If not do I have to put a <code>lock</code> around the loop or the <code>yield return</code>?</p>
  
  <p>Here is what I mean:</p>
  
  <p>Thread1 accesses the <code>Keys</code> property while Thread2 adds an item to the underlying dictionary. Is Thread1 affected by the add of Thread2?</p>