2016-05-12 88 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) 

}