Is there a difference between the '?? true' and the '== true' within an if statement?
bool? b = Jsonfile.GetBoolean("testval");
if (b ?? true) { }
if (b == true) { }
Yes, there is.
b ?? true
will match when b
is null
or true
b == true
will match when b
is not null
and is true
The difference is in the first line of the table (when b
is null
)
b b ?? true b == true
==== ========== ==========
null true false
true true true
false false false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With