嗨,大家好,如何在foreach中重複一個循環。如何在foreach中重複一個循環
foreach (string line in File.ReadLines("file.txt"))
{
// now line == "account", next line == "account1"
if (line.Contains("a"))
//next loop take "account1";
else
// need to set that next loop will take line == "account" again
}
怎麼辦呢?
你不能;改爲使用'for'。 – Nolonar
這個例子會被卡在一個循環中,反覆閱讀'賬戶'這一行......? –
這看起來像一個XY問題 - http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem。你能解釋一下你的代碼的總體意圖,因爲這個示例看起來很有缺陷嗎? – Kami