It's very convenient using inline sugar like that: obj?.func();
and obj ?? anotherObj
But I'm trying to find an alternative to the same approach in case I want to pull data from a dictionary without knowing whether the dictionary has the key I'm looking for or not.
Specifically I'd like to do something equivalent to:
someDictionary[someKey] ?? anotherValue
such that, if key exists it would use the corresponding value in the dictionary and if not, it will use anotherValue
. Obviously it's not possible to use as I wrote it here since it makes no sense, but the idea behind it is sound.
Is there a way to simplify it to be used inline, without making a separate check with if
?