title: Removing specific entries(defined in a List<string>) from Dictionary<string, int> gives critical error -->
body: <p>I have a List collection of strings. Like so,</p>
  <pre><code>    public List&lt;string&gt; filterWords = new List&lt;string&gt;()
      {
              &quot;an&quot; ,
              &quot;be&quot;,
              &quot; &quot;,
              &quot;in&quot;,
              &quot;the&quot;,
              &quot;of&quot;
              ..
          ...
          .
          . 
          ....
      };
  </code></pre>
  <p>I have a dictionary collection in format of Dictionary&lt;string, int&gt;, Like so,</p>
  <pre><code>    {{of, 2}},
      {{an, 4}},
      {{in, 7}},
      {{the, 8}},
      {{literate, 3}},
      {{culture, 5}},
      {{be, 5}},
      ...
      and so and so
  </code></pre>
  <p>Aim is to check/find out and remove from the above dictionary entries that contain keys from the previous list. ie an, be etcetc.</p>
  <p>Basic code I have put together so far is --</p>
  <pre><code>    public Dictionary&lt;string, int&gt; UniqueWordsDictionary(Dictionary&lt;string, int&gt; inputDict)
      {
          try
          {
              FilterWords flObj = new FilterWords();
  
              var dictionary = new Dictionary&lt;string, int&gt;();
  
              int idx = 0;
  
              var wordsToRemove = flObj.filterWords
                  .Select(record =&gt; record.Substring(0, record.IndexOf(',')));
  
              foreach(string wrd in wordsToRemove)
              {
                  inputDict.Remove(wrd);
              }
  
              dictionary = inputDict;
  
              return dictionary;
          }
          catch(Exception exp)
          {
              throw exp.GetBaseException();
          }
      }
  </code></pre>
  <p>The logic probably wrong. Exception I am getting
  <em><strong>An item with the same key has already been added</strong></em>.</p>
  <p>The stack trace -</p>
  <pre><code>    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at    System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) 
      at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) at ....
  </code></pre>
  <p>idx=0 been used, because I simply need a default value of 0 in the values of the dictionary. Logic seemed ok. What's a very sharp, precise solution for this. Any critical lambda expression that can do the needful? What is wrong with the foreach on 'wordsToRemove' ?</p>
  <p>Observe my posted code block. There's a commented line      <em><strong>dictionary=wordsToRemove.Select .............</strong></em>
  I tried alternatively commenting in that one and the foreach loop dictionary.Add. Error is same in both cases.</p>
  <p>** read comments added to code block closely
  Thx.</p>