title: Is there any implementation to Remove by Key and get the Value at the same time?
body: <p>I'm doing a performance critical program (little academic stuff) and I'm looking to optimize wherever possible (not like it proved "this is the" bottleneck).</p>
  
  <p>I have a custom dictionary structure (a wrapper around .NET <code>Dictionary&lt;,&gt;</code>) and I would constantly Remove items at one stage (by the <code>Key</code> value). I need the <code>Value</code> of the removed items. Right now I have to do:</p>
  
  <pre><code>T t;
  if !TryGet(key, out t)
     return false;
  
  Remove(key);
  </code></pre>
  
  <p>That's two lookups. I would love this:</p>
  
  <pre><code>public bool Remove(S key, out T value)
  {
      // implementation
  }
  </code></pre>
  
  <p>I know there is nothing in the framework, but is there an implementation somewhere? If so I would change my backing dictionary with that one.</p>
  
  <p><strong>Edit:</strong> Hmm I know both <code>TryGetValue</code> and <code>Remove</code> are O(1). Just knowing if there is any collection structure that would give the same effect in just one lookup. As I said I'm trying to optimize as much as possible. Just knowing.</p>