我想從if
語句中跳過List<T>.ForEach()
循環的迭代。如何從列表中跳出<T> .ForEach()循環來自C#中的if語句內部
我的代碼:
instructions.ForEach(delegate(Instruction inst)
{
if (!File.Exists(inst.file))
{
continue; // Jump to next iteration
}
Console.WriteLine(inst.file);
});
但是編譯器指出沒有任何東西可以跳出(大概是因爲它似乎走,如果塊作爲封閉塊?)。
有沒有辦法做到以上?喜歡的東西parentblock.continue;
等
感謝
什麼是錯的或循環的foreach應用謂詞? – 2012-07-26 15:37:32
這不是你的問題的答案,但爲什麼不只是使它成爲一個積極的檢查,並在if中移動你的邏輯? 'if(File.Exists){do stuff}'而不是如果不繼續? – MNGwinn 2012-07-26 15:39:19