gpt4 book ai didi

c# - 表达式 `?`中的符号 `maxY = (maxY > pt.Y) ? maxY : pt.Y;`是什么意思

转载 作者:行者123 更新时间:2023-11-30 18:50:02 26 4
gpt4 key购买 nike

符号?在下面的代码中是什么意思:

  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.Xfirst_expression
  • minXsecond_expression

这意味着如果条件为trueminX 的值将等于pt.X,否则它不会改变,因为第二个表达式本身就是变量。

关于c# - 表达式 `?`中的符号 `maxY = (maxY > pt.Y) ? maxY : pt.Y;`是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21868501/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com