title: C# Update entries of a dictionary in parallel?
body: <p>No idea if this is possible, but rather than iterate over a dictionary and modify entries based on some condition, sequentially, I was wondering if it is possible to do this in parallel?</p>
  
  <p>For example, rather than:</p>
  
  <pre><code>Dictionary&lt;int, byte&gt; dict = new Dictionary&lt;int, byte&gt;();
  for (int i = 0; i &lt; dict.Count; i++)
  {
      dict[i] = 255;
  }
  </code></pre>
  
  <p>I'd like something like:</p>
  
  <pre><code>Dictionary&lt;int, byte&gt; dict = new Dictionary&lt;int, byte&gt;();
  dict.Parallel(x=&gt;x, &lt;condition&gt;, &lt;function_to_apply&gt;);
  </code></pre>
  
  <p>I realise that in order to build the indices for modifying the dict, we would need to iterate and build a list of ints... but I was wondering if there was some sneaky way to do this that would be both faster and more concise than the first example.</p>
  
  <p>I could of course iterate through the <code>dict</code> and for each entry, spawn a new thread and run some code, return the value and build a new, updated dictionary, but that seems really overkill.</p>
  
  <p>The reason I'm curious is that the <code>&lt;function_to_apply&gt;</code> might be expensive.</p>