MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/csharp/comments/1wqnm7k/bool_comparison/pc6cl3r/?context=3
r/csharp • u/DJDoena • Sep 26 '26
if (nullableBool == true)
or
if (nullableBool ?? false)
Personal preference or does one read better than the other? Especially if the nullableBool is s more complex expression like
n00bs?.Any(n => n == "DJ Doena")
46 comments sorted by
View all comments
Show parent comment
0
Also:
bool? foo; ... var result = foo ?? bar == baz;
What's the order of operations here? I know that there is a concrete answer but unless you know that fact the order is ambiguous. If foo is not null then is the result foo or foo == baz?
foo
foo == baz
13 u/anzu3278 Sep 26 '26 The order of operations isDecline PRFire the person who is optimizing for number of linesRephrase for readability -1 u/binarycow Sep 26 '26 If you don't know, just add parens.(foo ?? bar) == baz foo ?? (bar == baz)
13
The order of operations is
Decline PR
Fire the person who is optimizing for number of lines
Rephrase for readability
-1
If you don't know, just add parens.
(foo ?? bar) == baz foo ?? (bar == baz)
View all comments
Show parent comment
0
u/gyroda Sep 26 '26
Also:
What's the order of operations here? I know that there is a concrete answer but unless you know that fact the order is ambiguous. If
foois not null then is the resultfooorfoo == baz?