我在循環「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