title: What is the best way to modify a list in a 'foreach' loop?
body: <p>A new feature in C# / .NET 4.0 is that you can change your enumerable in a <code>foreach</code> without getting the exception. See Paul Jackson's blog entry <em><a href="https://web.archive.org/web/20160308065012/www.lovethedot.net/2009/03/interesting-side-effect-of-concurrency.html" rel="noreferrer">An Interesting Side-Effect of Concurrency: Removing Items from a Collection While Enumerating</a></em> for information on this change.</p>
  <p>What is the best way to do the following?</p>
  <pre><code>foreach(var item in Enumerable)
  {
      foreach(var item2 in item.Enumerable)
      {
          item.Add(new item2)
      }
  }
  </code></pre>
  <p>Usually I use an <code>IList</code> as a cache/buffer until the end of the <code>foreach</code>, but is there better way?</p>