What is default value of `KeyValuePair`? [duplicate]

The default value of any type T is default(T), so for 100% theoretical accuracy you would write

if (!mapping.Equals(default(KeyValuePair<string, int>))) {
    // ...
}

Since KeyValuePair is a struct (i.e. a value type) you cannot compare it to null. Irrespective of that, comparing values with == is wrong as a default approach because if used on reference types it normally checks for reference equality.

Leave a Comment

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