Question mark and colon in statement. What does it mean?
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.
It's a ternary operator, or the short form for if..else
.
condition ? value if true : value if false
See Microsoft Docs | ?:
operator (C# reference).
It is the ternary conditional operator.
If the condition in the parenthesis before the ?
is true, it returns the value to the left of the :
, otherwise the value to the right.
string requestUri = _apiURL + "?e=" + OperationURL[0] + ((OperationURL[1] == "GET") ? GetRequestSignature() : "");
can be translated to:
string requestUri="";
if ((OperationURL[1] == "GET")
{
requestUri = _apiURL + "?e=" + GetRequestSignature();
}
else
{
requestUri = _apiURL + "?e=";
}