title: c# ToDictionary with ContainsKey check
body: <p>I have a list that I want to put in a dictionary, for simplicity the values being inserted will all be the same. </p>
  
  <p>I can use a foreach loop.</p>
  
  <pre><code>    List&lt;string&gt; list = new List&lt;string&gt;();
      list.Add("Earth");
      list.Add("Wind");
      list.Add("Fire");
      list.Add("Water");
      list.Add("Water"); // Will NOT BE INSERTED using the foreach loop
  
      var myDictionary= new Dictionary&lt;string, int&gt;();
      foreach (string value in list)
      {
          if (!myDictionary.ContainsKey(value))
          {
          myDictionary.Add(value, 1);
          }
      }
  </code></pre>
  
  <p>The above works.</p>
  
  <p>But I want to use ToDictionary do the same in the following way - </p>
  
  <pre><code>    Dictionary&lt;string, int&gt; myDictionary2 = list.ToDictionary(i =&gt; i, i =&gt; 1);
  </code></pre>
  
  <p>Of course this fails because I'm adding "Water" twice. </p>
  
  <p>What is the correct way of checking for duplicate entries when using ToDictionary?</p>