开发者

Skip a row in a for each rowset loop in c#

I am looping through a dataset for each data row

开发者_StackOverflow
 foreach (DataRow DRow in ds.Tables[0].Rows)

I would like to jump the current row when ever a if statement is true. Any clue how to do it?

Thanks in advance !


Use continue:

 foreach (DataRow DRow in ds.Tables[0].Rows)
 {
     if(expression) 
         continue;
 }

continue skips the remaining part of the foreach block for the current element an continues at the next new element in your collection.


Try this:

foreach (DataRow DRow in ds.Tables[0].Rows)
{
    if(true) // escape condition met
         continue;
}


You are looking for the continue keyword...

foreach (DataRow DRow in ds.Tables[0].Rows) {
    if(condition)
        continue;
}


The continue; instruction tells a loop to skip the rest of the code and move to the next iteration.

foreach (DataRow DRow in ds.Tables[0].Rows)
{
    if (--condition here--) continue;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜