Possible Duplicate:
Benefits of using the conditional ?: (ternary) operator
hi, I'm viewing this freesource library and I saw this weird - at least for me - syntax
*currFrame = ( ( diff >= differenceThreshold ) || ( diff <= differenceThresholdNeg ) ) ? (byte) 255 : (byte) 0;
currFrame is of type byte
diff, differenceThreshold and differenceThresholdNeg are of type Int.
What does the question mark do ? , what is this weird assign sentence suppose to mean ?
Thanks in advance
The conditional operator (?:) returns one of two values depending on the value of a Boolean expression. Following is the syntax for the conditional operator.
condition ? first_expression : second_expression;
C# reference: http://msdn.microsoft.com/en-us/library/ty67wk28.aspx
In your case currFrame will be assigned a value of 255 if ( diff >= differenceThreshold ) || ( diff <= differenceThresholdNeg )
is true
, otherwise value 0 will be assigned.
this is the same as
if(( diff >= differenceThreshold ) || ( diff <= differenceThresholdNeg ) )
currFrame = (byte) 255
else
currFrame = (byte) 0
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