开发者社区> 问答> 正文

条件运算符,编译报错 ?报错

项目中应用条件运算符?报错:只有 assignment、call、increment、decrement、await 和 new 对象表达式可用作语。
写了个最简单的测试代码,问题依旧:

 int i = 0;
string str = "";
 i == 0 ? str = "true" : str = "false";

编译照样报错:只有 assignment、call、increment、decrement、await 和 new 对象表达式可用作语。
查看MSDN也不明白,请老师们指点下迷津,谢啦!

展开
收起
爱吃鱼的程序员 2020-06-23 01:01:34 409 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    str=(i==0?"true":"false");

    注意只能跟表达式radioButtonR1_YES.Checked=true语句,不是表达式

    我的实际代码是这样的(处理RadioButton选项):

    cl.ChildNodes[1].ChildNodes[2].InnerText.ToLower()=="true"?radioButtonR1_YES.Checked=true:radioButtonR1_NO.Checked=true;

    不太好按照caozhy的方式改造...是不是我这样的思路不对?

    如果你无聊非要用,可以这么写CheckBoxch=cl.ChildNodes[1].ChildNodes[2].InnerText.ToLower()=="true"?radioButtonR1_YES.:radioButtonR1_NO;ch.Checked=true;
    2020-06-23 01:01:50
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关实验场景

更多