What do the question mark (?
) and colon (:
) mean?
((OperationURL[1] == "GET") ? GetRequestSignature() : "")
It appears in the following statement:
string requestUri = _apiURL + "?e=" + OperationURL[0] + ((OperationURL[1] == "GET") ? GetRequestSignature() : "");
Unlike all other operators in Objective-C—which are either unary or binary operators—the conditional operator is a ternary operator; that is, it takes three operands. The two symbols used to denote this operator are the question mark ( ? ) and the colon ( : ).
The conditional or question mark operator, represented by a ? , is one of the most powerful features in JavaScript. The ? operator is used in conditional statements, and when paired with a : , can function as a compact alternative to if...else statements. But there is more to it than meets the eye.
“Question mark” or “conditional” operator in JavaScript is a ternary operator that has three operands. The expression consists of three operands: the condition, value if true and value if false. The evaluation of the condition should result in either true/false or a boolean value.
It's sometimes just called "the ternary operator", but it's not the only ternary operator, just the most common one.
This is the conditional operator expression.
(condition) ? [true path] : [false path];
For example
string value = someBooleanExpression ? "Alpha" : "Beta";
So if the boolean expression is true, value will hold "Alpha", otherwise, it holds "Beta".
For a common pitfall that people fall into, see this question in the C# tag wiki.
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