title: LINQ performance vs. Dictionary<K,V>
body: <p>In many situations, for simplicity's sake, I would have preferred to use a List or an HashSet in combination with LINQ instead of using a Dictionary. However, I usually sticked with Dictionary because I thought Dictionary would be more performant because of its hash table implementation.</p>
  
  <p>For example:</p>
  
  <p>When I do this in LINQ:</p>
  
  <pre><code>bool exists = hashset.Any(item =&gt; item.Key == someKey);
  </code></pre>
  
  <p>Do I lose significant performance compared to the following equivalent with a Dictionary?</p>
  
  <pre><code>bool exists = dictionary.ContainsKey(someKey); // an O(1) operation
  </code></pre>
  
  <p>Are the LINQ queries optimized in some way that would make them a justifiable choice against a Dictionary? Or is the above Any() a plain O(n) operation no matter on which type of collection it is executed?</p>