Let\'s assume I have a class that has a property of type Dictionary, that may be null.
This compiles but the call to TryGetVa
That's because if c.PossiblyNullDictionary is null, TryGetValue won't be executed and that expression won't return true or false.
c.PossiblyNullDictionary ?. TryGetValue("someKey", out val) returns Nullable, you can replace your code with something like this and will compile:
string val;
var result = c.PossiblyNullDictionary?.TryGetValue("key", out val);
if (result.HasValue && result.Value)
{
}