How can we verify (.NET 2) if a KeyValuePair has a value assigned or not?
Dim pair as KeyValuePair(Of A, B) = Nothing
if pair.??? Then Return
As is it a structure, it can’t be verified with pair Is Nothing.
Point structure, by eg. has a p.IsEmpty verification.
Rather than using the “normal” type here – which means you can’t detect the difference between a value with the default values of
AandBas the key and value, you should use aNullable(Of KeyValuePair(Of A, B)).Effectively you’re asking exactly the same question as asking whether an
Integervariable has a value, where setting it toNothingwould give it a value of 0. How can you tell the difference between that 0 and a “real” 0? You can’t – which is whyNullable(Of T)exists in the first place. The exact same logic applies toKeyValuePair.