c# – 为什么PHP会产生意外的输出?
发布时间:2020-12-15 23:26:29 所属栏目:百科 来源:网络整理
导读:$i = 2;$result = ($i == 2) ? "Two" : ($i == 1) ? "One" : "Other";echo $result; // outputs: One 虽然C#输出中的代码相同:两个 int i=2;String result = (i == 2) ? "Two" : (i == 1) ? "One" : "Other" ;Console.Write( result ); // outputs: Two 解
$i = 2; $result = ($i == 2) ? "Two" : ($i == 1) ? "One" : "Other"; echo $result; // outputs: One 虽然C#输出中的代码相同:两个 int i=2; String result = (i == 2) ? "Two" : (i == 1) ? "One" : "Other" ; Console.Write( result ); // outputs: Two 解决方法
三元运算符被评估为LEFT-TO-RIGHT.
($i == 2) ? "Two" : ($i == 1) ? "One" : "Other" "Two" ? "One" : "Other" // first part evaluated to "Two" "One" // non-empty strings evaluate to true 所以你应该在你的输出中得到一个,而不是其他.这有点棘手. 来自manual的明智之词:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |