title: What changed in .net 5 that makes it not throw when changing dictionary values in foreach
body: <p>In .NET&lt;5 and .NET Core 3.1 the following code</p>
  <pre><code>var d = new Dictionary&lt;string, int&gt; { { &quot;a&quot;, 0 }, { &quot;b&quot;, 0 }, { &quot;c&quot;, 0 } };
  foreach (var k in d.Keys) 
  {
     d[k]+=1;
  }
  </code></pre>
  <p><strong>throws</strong></p>
  <blockquote>
  <p>System.InvalidOperationException: Collection was modified; enumeration operation may not execute.</p>
  </blockquote>
  <p>When targeting .NET 5 the snippet no longer throws.</p>
  <p>What has changed?</p>
  <p>I failed to find the answer in <a href="https://docs.microsoft.com/en-us/dotnet/core/compatibility/5.0" rel="noreferrer">Breaking changes in .NET 5</a> and <a href="https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-5/" rel="noreferrer">Performance Improvements in .NET 5</a>.</p>
  <p>Is it something to do with <code>ref readonly T</code>?</p>