C#语法里面问号 [英] question mark inside C# syntax
问题描述
可能重复:结果
的优点:(三元)运算符
我是查看此freesource库,我看到了这个奇怪的 - 至少对我来说 - 语法
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是类型字节的
差异,differenceThreshold和differenceThresholdNeg是int类型的。
diff, differenceThreshold and differenceThresholdNeg are of type Int.
什么是问号呢? ,这是什么奇怪的分配句话想什么意思?
What does the question mark do ? , what is this weird assign sentence suppose to mean ?
在此先感谢
推荐答案
在条件运算符(?:)返回根据布尔表达式的值两个值之一。以下是条件运算符的语法。
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#参考:的 http://msdn.microsoft.com/en-us/library/ty67wk28.aspx
C# reference: http://msdn.microsoft.com/en-us/library/ty67wk28.aspx
在你的情况currFrame如果将分配值为255(DIFF> = differenceThreshold)|| (DIFF< = differenceThresholdNeg)
是真正
,否则值为0将被分配
In your case currFrame will be assigned a value of 255 if ( diff >= differenceThreshold ) || ( diff <= differenceThresholdNeg )
is true
, otherwise value 0 will be assigned.
这篇关于C#语法里面问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!