KeyValuePair<K,V>
is a struct, not a class. It's like doing:
int i = 10;
if (i != null) ...
(Although that is actually legal, with a warning, due to odd nullable conversion rules. The important bit is that the if
condition will never be true.)
To make it "optional", you can use the nullable form:
static void Foo(KeyValuePair<object,string>? pair)
{
if (pair != null)
{
}
// Other code
}
Note the ? in KeyValuePair<object,string>?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…