Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question mark and colon in statement. What does it mean?

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() : ""); 
like image 394
001 Avatar asked Aug 05 '11 13:08

001


People also ask

What does question mark and colon mean in C?

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 ( : ).

What does question mark mean in syntax?

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.

What does the question mark operator mean?

“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.

What is the other name for a question mark colon?

It's sometimes just called "the ternary operator", but it's not the only ternary operator, just the most common one.


1 Answers

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.

like image 172
Anthony Pegram Avatar answered Sep 20 '22 12:09

Anthony Pegram