I am using nullable doubles to store the sum of some values pulled from various sources. The sum could be any real value or null if no elements are present.
Currently, I use a null check and either assign or increment:
double? sum = null;
...
if(sum == null)
sum = someTempValue;
else
sum += someTempValue;
I know c# has several shorthand null checks for method calls and the such. My question is if there is a shorthand notation to the addition assignment operator +=
when using nullables that assigns the value if null
or performs the operation if not null
?