布尔? :操作语法 [英] Boolean ? : operation syntax
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/2595392/what-does-the-question-mark-and-the-colon-ternary-operator-mean-in-objectiv\">What没有问号和冒号(?:三元运算符)?在平均Objective-C的
我见过code其中它使用的语法类似...
I have seen code where it uses a syntax something like...
someValue = someBoolean ? valueOne : valueTwo;
或者这样的事情。
Or something like this.
我从来没有使用过这一点,我不知道它叫什么。
I've never used this and I'm not sure what it's called.
请有人可以解释如何使用它,或者提供有关其链接到一个资源。
Please can someone explain how to use it or provide a link to a resource about it.
推荐答案
这是三元opertaor。
It's ternary opertaor.
据评估 someBoolean
的条件。
如果这是真的,然后通过 valueOne
到 someValue中
If it is true then pass the valueOne
to someValue
如果它是假的,然后通过 valueTwo
到 someValue中
If it is false then pass valueTwo
to someValue
这等于:
if(someBoolean)
{
someValue = valueOne;
}
else
{
someValue = valueTwo;
}
这是一个很好的链接,解释了有关三元操作
This is a good link which explains about ternary operator
这篇关于布尔? :操作语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!