作者apologize (人生在世很惬意)
看板C_Sharp
标题[问题] ?: 运算子的问题
时间Mon Jan 5 16:15:55 2015
checkBox1.Checked == true ? timer1.Enabled = true : timer1.Enabled = false;
我是这样写,可是他说只能用陈述式表示,
可是不是要判别式才能用?请问要怎样修改?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 220.130.129.3
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1420445757.A.3E8.html
1F:推 Peruheru: string str = (A == B ? "成立" : "不成立") ; 01/05 16:18
2F:→ Peruheru: ?:并不是"执行里面的结果",而是"传回里面的结果" 01/05 16:19
3F:→ Peruheru: t1.Enabled = chkBox1.Checked == true ? true : false; 01/05 16:20
4F:→ Peruheru: 这才是这个运算子的用法 01/05 16:21
5F:→ Peruheru: 话说你的叙述直接使用timer1.Enabled = checkBox1.Check 01/05 16:21
6F:→ Peruheru: 不就好了? 01/05 16:21
7F:→ Peruheru: 其实我那样讲也不对,里面的运算还是会执行 01/05 16:22
8F:→ Peruheru: 只是他的重点在於执行完会传回执行结果,你要的是结果 01/05 16:23
9F:推 cjcat2266: timer1.Enabled = checkBox1.Checked +1 01/06 10:12