Why does null-conditional operator not evaluate the entire expressions? #7691
Replies: 1 comment 11 replies
-
Beta Was this translation helpful? Give feedback.
11 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I like to use null-conditional operators if there are some values in my code that are likely to be null. It turns out I was using it wrong until now.
I think that the following
foo?.Bar?.ToLower() != foo2?.Bar?.ToLower()
lines are executed because they evaluate as equivalentfoo?.Bar?.ToLower() != null
. What I mean is that next objects are not checked if they are null or not. But I was expecting include all references and all their properties likefoo2, foo2.Bar
and all their properties inif
expression andfoo.Do()
method to not be executed. So, why the operator doesnt work like this?Beta Was this translation helpful? Give feedback.
All reactions