if (value2 != null)
{
value1 = value2;
}
? and ?? operators don't seem to be useful here. I thought of using the ternary operator.
value1 = (value2 != null) ? value2 : value1;
Doesn't seem good. Is there a shorter way?
if (value2 != null)
{
value1 = value2;
}
? and ?? operators don't seem to be useful here. I thought of using the ternary operator.
value1 = (value2 != null) ? value2 : value1;
Doesn't seem good. Is there a shorter way?
Copyright © 2021 Jogjafile Inc.
It seems that this is the closest:
I feel like your original
if
is more readable.The
??
operator is most useful if you use it within an expression. Like this: