3 of 3
replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
int v = b ? (a ? 1 : 2) : (a ? 0 : 1);
EDIT #1:
As per svick, parsed out conditional operator on separate lines:
int v = b
? (a ? 1 : 2)
: (a ? 0 : 1);
EDIT #2:
Here's one I don't like, but it has no branching whatsoever:
int v = Convert.ToInt32(b) + Convert.ToInt32(!a);
Jesse C. Slicer
- 14.5k
- 1
- 40
- 54
default