Why can’t I compare a KeyValuePair with default

This happens because KeyValuePair<TKey, TValue> does not define a custom == operator and is not included in the predefined list of value types that can use it.

Here is a link to the MSDN documentation for that operator.

For predefined value types, the equality operator (==) returns true if the values of its operands are equal, false otherwise.

Your best bet for an equality check in this case, because this is not a struct you have control over, is to call default(KeyValuePair<TKey,TValue>).Equals(pair) instead.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)