c#循环中的每个进度循环

时间:2016-05-12 14:35:19

标签: c# asp.net-webpages

我遇到的情况是我使用记录中的每条记录循环遍历c#webpages数据库记录集。

在该循环中,我还想执行另一个do while循环,以便将记录组合​​在一起。

是否有可能在循环中增加for next循环的迭代...硬解释但是这样的事情

 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 个答案:

答案 0 :(得分:0)

最好为这种方法做一个for循环

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)

}
相关问题