c# - 关于包含的表达式名称的简单问题?:
问题描述
有谁知道这个表达式的名字是什么?
bool result = array[i] == 1 ? true : false;
解决方案
该运算符? :
通常称为三元运算符。它在许多语言中被称为三元运算符,而不仅仅是 C#。
它具有以下语法:
condition ? consequent : alternative
从上面链接的文档中:
您可以使用以下助记符来记住条件运算符是如何计算的:
is this condition true ? yes : no
它是常规 if/else 语句的简写。
int result;
if (condition)
{
result = 1;
}
else
{
result = 0;
}
上面的三元语法等价于:
int result = condition ? 1 : 0;
推荐阅读
- javascript - 如何使用 express node.js 在 mongodb 中保存数据?
- java - 飞碟pdf:未显示希腊字符
- javascript - bootstrap - 如何填写下拉列表
- python - 打印列表时如何将单词添加到列表中而不用逗号分隔?
- powerbi - 替代组件或错误解决方案
- java - 订阅特权 STOMP 主题时抛出错误:无法向 ExecutorSubscribableChannel[clientInboundChannel] 发送消息
- java - 减少协议缓冲区消息大小的选项
- c# - C# XML 将子节点名称与父名称和值合并
- ffmpeg - 试图用 cuda 和 chromakey/colorkey 加速 ffmpeg
- javascript - 为什么我声明的函数中的递归不起作用?