title: How to dynamically remove key value pair from a dictionary if the key contains some substring?
body: <p>I have an outer loop iterating over an array of substrings to be matched in the dictionary. In the inner loop I want to iterate over the dictionary and delete an entry whose key contains a substring.How to do this without getting "Collection was modified Exception"?</p>
  
  <pre><code>foreach (string outerKey in new string[] { "PAYERADDR_PAYERNAME", "RECADDR_RECNAME", "PAYERADDR_ADDR", "RECADDR_ADDR" })
  {
      foreach (var item in _generalWorksheetData.Where(kvp =&gt; kvp.Value.Contains(outerKey)).ToList())
          {
              _generalWorksheetData.Remove(item.Key);
          }
  }
  </code></pre>