title: Should a .NET generic dictionary be initialised with a capacity equal to the number of items it will contain?
body: <p>If I have, say, 100 items that'll be stored in a dictionary, should I initialise it thus?</p>
  
  <pre><code>var myDictionary = new Dictionary&lt;Key, Value&gt;(100);
  </code></pre>
  
  <p>My understanding is that the .NET dictionary internally resizes itself when it reaches a given loading, and that the loading threshold is defined as a ratio of the capacity.</p>
  
  <p>That would suggest that if 100 items were added to the above dictionary, then it would resize itself when one of the items was added.  Resizing a dictionary is something I'd like to avoid as it has a performance hit and is wasteful of memory.</p>
  
  <p>The probability of hashing collisions is proportional to the loading in a dictionary.  Therefore, even if the dictionary does not resize itself (and uses all of its slots) then the performance must degrade due to these collisions. </p>
  
  <p>How should one best decide what capacity to initialise the dictionary to, assuming you know how many items will be inside the dictionary?</p>