title: Why can't I compare a KeyValuePair<TKey, TValue> with default
body: <p>In .Net 2.5 I can usually get an equality comparison (==) between a value and its type default</p>
  
  <pre><code>if (myString == default(string))
  </code></pre>
  
  <p>However I get the following exception when I try to run an equality comparison on a default KeyValuePair and a KeyValuePair</p>
  
  <p>Code Sample (from a pre-extension method, proto-lambda static ListUtilities class :) )</p>
  
  <pre><code>public static TKey 
          FirstKeyOrDefault&lt;TKey, TValue&gt;(Dictionary&lt;TKey, TValue&gt; lookups, 
                     Predicate&lt;KeyValuePair&lt;TKey, TValue&gt;&gt; predicate)
  {
      KeyValuePair&lt;TKey, TValue&gt; pair = FirstOrDefault(lookups, predicate);
  
      return pair == default(KeyValuePair&lt;TKey, TValue&gt;) ? 
                     default(TKey) : pair.Key;
  }
  </code></pre>
  
  <p>Exception:</p>
  
  <blockquote>
    <p>Operator '==' cannot be applied to
    operands of type
    'System.Collections.Generic.KeyValuePair&lt;string,object>'
    and
    'System.Collections.Generic.KeyValuePair&lt;string,object>'</p>
  </blockquote>
  
  <p>Is it because, as a struct, the KeyValuePair is not nullable? If this is the case, why, as, presumably, default was implemented to handle not nullable types?</p>
  
  <p><strong>EDIT</strong> </p>
  
  <p>For the record, I chose @Chris Hannon as selected answer, as he gave me what I was looking for, the most elegant option, and a succinct explanation, however I do encourage reading @Dasuraga for a very comprehensive explanation as to why this is the case</p>