I will appreciate a logical explanation to this line of code. What will it achieve?
x = y ?? "";
where x
is of type object and y
is string variable.
Please note that the program compiled.
I will appreciate a logical explanation to this line of code. What will it achieve?
x = y ?? "";
where x
is of type object and y
is string variable.
Please note that the program compiled.
it will assign an empty string to x if y is null
it is called null-coalescing operator.
for example if you have
a = b ?? c ?? d ?? e ?? f;
then it will look for b
value. if it is not null then a=b
if b
is null it will check for c
value. if it is not null then a=c
.
if c
is null also then it will check for ... (go on)
This translates into the long statement.
if(y != null)
{
x = y;
}
else
{
x = "";
}