【发布时间】:2012-07-24 17:18:13
【问题描述】:
三元运算符有一个简写版本,即
var = exp ?: exp2
我知道它适用于 PHP。其他语言可能也采用了它。 C# 具有类似的功能(对于这个问题的上下文)-??。
当条件通过时,是重新计算表达式,还是将结果存储在某个地方?
【问题讨论】:
-
等等,问题是关于什么语言的?
标签: ternary-operator conditional-operator
三元运算符有一个简写版本,即
var = exp ?: exp2
我知道它适用于 PHP。其他语言可能也采用了它。 C# 具有类似的功能(对于这个问题的上下文)-??。
当条件通过时,是重新计算表达式,还是将结果存储在某个地方?
【问题讨论】:
标签: ternary-operator conditional-operator
http://msdn.microsoft.com/en-us/library/ms173224.aspx
The ?? operator is called the null-coalescing operator and is used to define a default value for nullable value types or reference types. It returns the left-hand operand if the operand is not null; otherwise it returns the right operand.
它被存储,而不是计算两次。
【讨论】: