简体   繁体   English

在C#中为每个行集循环在A中跳过一行

[英]Skip a row in a for each rowset loop in c#

I am looping through a dataset for each data row 我正在遍历每个数据行的数据集

 foreach (DataRow DRow in ds.Tables[0].Rows)

I would like to jump the current row when ever a if statement is true. 如果if语句为true,我想跳过当前行。 Any clue how to do it? 有什么线索怎么做?

Thanks in advance ! 提前致谢 !

Use continue : 使用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. continue跳过当前元素的在foreach块的剩余部分将继续在您的收藏在接下来的新元素。

Try this: 尝试这个:

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

You are looking for the continue keyword... 您正在寻找continue关键字...

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

The continue; 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM