I don't think adding a boolean flag to some value is a very readable solution. Basically you want to increase (e.g. add 1) the value if the flag true. So, simply, if the check will clearly describe your intention to add to do the work:
if (flag) value++;
UPDATE: according to your editing you want to do two things:
- Set the default value to a value with a zero value
- The value of the increment if any condition is true.
To make your code clear, I would not put both things on the same line. Make your intention explicit:
value = value ?? 0;
if (flag)
value++;
source
share