我刚开始使用 C#,我被编译错误弄糊涂了。这是代码:namespace Control_Flow_1{ class Program { static void Main(string[] args) { string UserInput; int Number; Console.WriteLine("Bitte geben sie eine Nummer von 1-10 ein"); UserInput = Console.ReadLine(); Number = Convert.ToInt32(UserInput); if (Number >= 1 && Number <= 10); { Console.WriteLine("Valid"); } else { Console.WriteLine("Invalid"); } } }}Console.WriteLine; 之后的 } 似乎由于某种原因执行编译错误,如何解决?
1 回答
![?](http://img1.sycdn.imooc.com/54584e2c00010a2c02200220-100-100.jpg)
撒科打诨
TA贡献1934条经验 获得超2个赞
if (Number >= 1 && Number <= 10); 去掉分号。
在if你之后加分号
if ()
a block of code
else (with no corresponding if)
a block of code
分号结束if语句,所以你有一个else没有以前的“浮动”if
- 1 回答
- 0 关注
- 167 浏览
添加回答
举报
0/150
提交
取消