可能重複:
continue and break with an extended scopeC#爲繼續裏面的foreach
我有一個問題。我不知道如何在foreach內部繼續調用「for」。
代碼:
for(int i = 0; i < ...; i++)
{
foreach(´´ .. in ´´)
{
if(,,.Value == null)
// A!
}
}
,我需要更換 「A」!代碼繼續「for」!不是foreach。我使用基本的繼續,但它只適用於foreach。
解決 有:
for(int i = 0; i < ...; i++)
{
bool Ab = false;
foreach(´´ .. in ´´)
{
if(,,.Value == null)
Ab = true;
}
if(Ab)
continue;
}
你在循環什麼樣的對象?有可能比使用foreach ...更好的方法...如果...反模式。 – 2012-07-25 16:55:31
您不能,您需要使用變量將該信息傳遞給for循環。順便說一句,如果你接受一些答案,你會得到更好的答覆。 – Jodrell 2012-07-25 16:56:23
嘗試'break'而不是繼續在你的foreach循環中,這會導致執行從'foreach'掉下來並繼續'for'循環 – Nathan 2012-07-25 16:56:38