问号和语句中的冒号.这是什么意思? [英] Question mark and colon in statement. What does it mean?

查看:539
本文介绍了问号和语句中的冒号.这是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问号(?)和冒号(:)是什么意思?

What do the question mark (?) and colon (:) mean?

((OperationURL[1] == "GET") ? GetRequestSignature() : "")

它出现在以下语句中:

string requestUri = _apiURL + "?e=" + OperationURL[0] + ((OperationURL[1] == "GET") ? GetRequestSignature() : "");

推荐答案

这是条件运算符表达式.

This is the conditional operator expression.

(condition) ? [true path] : [false path];

例如

 string value = someBooleanExpression ? "Alpha" : "Beta";

因此,如果布尔表达式为true,则value将保留"Alpha",否则将保留"Beta".

So if the boolean expression is true, value will hold "Alpha", otherwise, it holds "Beta".

要了解人们经常遇到的陷阱,请参阅此问题 C#标签Wiki 中.

For a common pitfall that people fall into, see this question in the C# tag wiki.

这篇关于问号和语句中的冒号.这是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆