2016-05-12 86 views
-1

內的每一個進步循環我在那裏,我通過使用在記錄每個記錄一個C#網頁數據庫記錄循環的情況。C#爲循環

在這一圈我也想執行另一個do while循環,使記錄可以被組合在一起。

是否有可能增加的下一次循環迭代從loop..hard內解釋,但這樣的事情

foreach (var records in records){ 

do{ 
    <p>@records.NAME</p> 
    INCREASE THE FOREACH LOOP ITERATION HERE 
    currentName = records.NAME //this is now the next name in the recordset 
}while(currentName!=records.NAME) 

} 

感謝 羅爾夫

+1

你的意思是你想要去循環的下一次迭代?然後使用「繼續」。 – AntiTcb

+1

什麼是「記錄」類型?你可以考慮在索引器中使用'for',如果'records'是數組或者'List'例如 – Ian

+0

我想你應該看看LINQ的這些東西。可以像訂購它一樣簡單,然後在正常的foreach循環中循環顯示所有結果。你現在正在做的事似乎過於複雜。 – JaggenSWE

回答

0

最好是用於做循環這種類型的方法

for (int index = 0; index < records.Count - 1; index++){ 

do{ 
    <p>@((records)records.Item(index)).NAME</p> 
    index++; 
    If(index < records.Count) { 
     currentName = ((records)records.Item(index)).NAME; //this is now the next name in the recordset 
    Else{ 
     Break;//Breaks out of the while loop because you are done with the for loop } 
    } 
}while(currentName!=((records)records.Item(index)).NAME) 

}