title: I need a sorted Dictionary, but I would like to limit its capacity
body: <p>I have a <code>Dictionary&lt;..., Statistics&gt;</code>, where <code>Statistics</code> is a custom structure with some fields. This struct implements the <code>IComparer</code> interface.</p>
  
  <pre><code>public struct Statistics : IComparer&lt;Statistics&gt;
  {
      public UInt64 NumberOfOccurrences;
      public UInt64 TotalNumberOfWords;
      ...
  
      public int Compare(Statistics x, Statistics y)
      {
          // code for compare the statistics
          ...
      }
  }
  </code></pre>
  
  <p>I chose the dictionary to have better performance during updates of existing statistics.
  However, I also want good performance in reading statistics in order from best to worst, so I should use a <code>SortedDictionary</code> in place of <code>Dictionary</code>.</p>
  
  <p>Now I would like to limit the number of entries within the dictionary to a specified value, by removing the entries with worst statistics, <strong><em>in order to limit the memory usage</em></strong>.
  I have seen that <code>SortedDictionary</code> does not have constructors with a <code>capacity</code> argument, so I thought I'd store the <em>maximum number of entries</em> in the integer variable <code>elementsCountLimit</code>. Before adding a new entry in the <code>SortedDictionary</code>, I could perform the following check:</p>
  
  <pre><code>if (dict.Count == elementsCountLimit)
  {
      // Remove the last entry, that is the
      // entry with worst statistics.
  }
  </code></pre>
  
  <ol>
  <li>But, If I don't know the key, how can I remove the last entry?</li>
  <li>How can I limit the memory usage?</li>
  </ol>