符号?
在下面的代码中是什么意思:
for(int i = 0 ; i < Hpts.BranchCount;i++)
{ foreach(Point3d pr in Hpts.Branches[i]){
minX = (minX > pt.X) ? pt.X : minX;
minY = (minY > pt.Y) ? pt.Y : minX;
maxX = (maxX > pt.X) ? maxX : pt.X;
maxY = (maxY > pt.Y) ? maxY : pt.Y;
}
}
最佳答案
它被称为条件运算符
。参见documentation
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;
The condition must evaluate to true or false. If condition is true, first_expression is evaluated and becomes the result. If condition is false, second_expression is evaluated and becomes the result. Only one of the two expressions is evaluated.
以你的情况为例:
minX = (minX > pt.X) ? pt.X : minX;
minX > pt.X
是条件pt.X
是 first_expressionminX
是second_expression
这意味着如果条件为true,minX
的值将等于pt.X
,否则它不会改变,因为第二个表达式本身就是变量。
关于c# - 表达式 `?`中的符号 `maxY = (maxY > pt.Y) ? maxY : pt.Y;`是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21868501/