What is the result if all the parameters of the zero coalescing operation are equal to zero?

When this code ends, what is the result myObject?

object myObject = "something";
object yourObject = null;

myObject = null ?? yourObject;
+3
source share
3 answers

myObject will be null

It translates to

if (null == null)
    myObject = yourObject;
else
    myObject = null;
+2
source

The coalesce statement translates to this:

x ?? y
x != null ? x : y

Therefore you have:

myObject = null != null ? null : yourObject;

This is actually pretty pointless since null will always be null.

+1
source

, :

A    ?? B    -> R
---------------------
a    ?? any  -> a; where a is not-null
null ?? b    -> b; for any b
null ?? null -> null; implied from previous

?? - (!) , x ?? y ?? zx ?? (y ?? z). && ||, ?? .

... ?? ( #):

(??) , NULL; .

... # 3.0:

a b , NULL . a , a? b - a; b. b , a null.

+1

Source: https://habr.com/ru/post/1770362/


All Articles