我在循环“while”的公共静态方法中编写了一些代码。但是这个循环在“if”语句之后结束,并且应用程序不会抛出任何异常。这里是代码:while ...循环在if语句公用静态方法后结束C#
public static void ShortcutDetect()
{
ShortkeyIndex = 0;
while(ShortkeyIndex < 1000)
{
File.WriteAllText(@"C:\Users\OEM\Desktop\log.txt",
File.ReadAllText(@"C:\Users\OEM\Desktop\log.txt") + Convert.ToString(ShortkeyIndex));
if(Program.key.Replace("LShiftKey","Shift")
.Replace("RShiftKey","Shift").Replace("RMenu","Alt")
.Replace("LMenu","Alt").Replace("RControlKey","Ctrl")
.Replace("LControlKey","Ctrl").EndsWith(RawShortkeys[ShortkeyIndex]))
{
MessageBox.Show(RawShortkeys[ShortkeyIndex]);
}
ShortkeyIndex++;
}
}
事先感谢。
为什么would'n什么时候结束? 1000次迭代需要很短的时间。 – Guy
您如何得出“如果”声明“之后此循环结束”的结论?你是如何测试它的? –
你确定只有一个“循环”被执行?你调试了代码吗?从你发布的内容来看,没有迹象表明这一点。 – HimBromBeere