I have the following:
KeyValuePair<string, string>? myKVP;
// code that may conditionally do something with it
string keyString = myKVP.Key;
// throws 'System.Nullable<System.Collections.Generic.KeyValuePair<string,string>>'
// does not contain a definition for 'Key'
I’m sure there is some reason for this as I can see that the type is nullable. Is it because I am trying to access the key when null could cause bad things to happen?
Try this instead:
Here is a stripped down version of
System.Nullable<T>:Since the
Valueproperty is of typeTyou must use theValueproperty to get at the wrapped type instance that you are working with.Edit: I would suggest that you check the
HasValueproperty of your nullable type prior to using theValue.