I have a decimal variable that I would like to negate if a boolean variable is true. Can anyone think of a more elegant way to do it than this:
decimal amount = 500m;
bool negate = true;
amount *= (negate ? -1 : 1);
I’m thinking something along the lines of bitwise operators or a strictly mathematical implementation.
Personally, I would just use an if statement, since I feel that it’s the most clear in terms of intent:
This is really not any extra typing (it’s actually shorter!), and more clear in my opinion.