I have an integer variable which can contain either a 0 or a 1. It is not a boolean, rather a representation of an enum in C#.
What is the shortest way of rewriting this ternary function such that when sourceNumber is 1, targetNumber is set to 0, when sourceNumber is 0, targetNumber is set to 1?
var sourceNumber = 1;
var targetNumber = sourceNumber == 1 ? 0 : 1;
Short and efficient :
var targetNumber = 1 - sourceNumber;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With