【发布时间】:2017-04-10 16:09:13
【问题描述】:
我正在编码,但我遇到了 c# 问题。我有以下代码:
if (Console.ReadKey(true).KeyChar.ToString() == "l") // Reading single key in console
goto load;
// If not, continue
// Here, if I didn't press "l", I have to press the key once more, because at first, it checked it in if statement above so it is reding this into the string on the second time. So just want that if I didn't press "l" Automatically add that key to string below
string read = Console.ReadLine();
问题是,如果我不想按“l”的第一个字母,我必须按其他的 2 次。 (因为第一次按下正在检查 Console.ReadKey()。) 那么,如果我按下与“l”不同的键,我该如何做到这一点,它会自动将其写入下面的 Console.ReadLine?谢谢
【问题讨论】:
-
如果您的代码中有
goto,您将遇到更多问题 -
@UnholySheep 已经告诉他/她了,但是....
-
避免使用
goto语句,您可以改用if -
我删除了那个标签并转到这里,这也是同样的问题。
-
忠告,
DON'T use GOTO Statements\