title: How to Get Key-Value Pairs of a Specific Type Only from Dictionary
body: <p>I have an IDictionary (not generic, so I am dealing with <code>object</code>'s here), and I would like to get from it only the elements in that IDictionary which correspond to a specific key type K and a specific value type V. There are a billion ways to do this, but the most elegant way I have found seems to be this:</p>
  
  <pre><code>Dictionary&lt;K, V&gt; dict = myIDictionary.OfType&lt;KeyValuePair&lt;K, V&gt;&gt;();
  </code></pre>
  
  <p>This compiles fine so I am assuming this method CAN work for a dictionary (it's declared by IEnumerable) but the resulting dictionary is empty, although there are definitely KVPs in there that meet those conditions. Obviously I was assuming that <code>KeyValuePair&lt;K, V&gt;</code> is the format it is expecting, since that's what's used in enumeration over a dictionary, but is it something else? Is there something I'm missing?</p>