Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何根据给定的代码跳过foreach循环?_C#_Asp.net_Foreach - Fatal编程技术网

C# 如何根据给定的代码跳过foreach循环?

C# 如何根据给定的代码跳过foreach循环?,c#,asp.net,foreach,C#,Asp.net,Foreach,我有一个代码检查asp.net/c中的checkedlistbox复选框 foreach (ListItem item in cbxlFeatures.Items) { foreach (DataRow row in dt.Rows) { if (item.Value.Equals(row["Id"].ToString())) { item.Selected = Convert.ToBoolean(row["Id"]);

我有一个代码检查asp.net/c中的checkedlistbox复选框

foreach (ListItem item in cbxlFeatures.Items)
{
  foreach (DataRow row in dt.Rows)
    {
       if (item.Value.Equals(row["Id"].ToString()))
        {
          item.Selected = Convert.ToBoolean(row["Id"]); 
         // whenever this condition is met i need my 
         // loop to skip the remianing iterations and start with next one.

        }
         break;
     }
 }
更新


我想,我的问题不清楚。假设我的数据表中有1到10个ID。其中7,8,9的值为false,其余为true。这个id也显示在复选框列表上。只是我的真/假值不同。所以我要求检查条件并将值t/f设置为复选框。一旦复选框设置为选中,循环将跳过。

我想您正在寻找关键字continue

请使用continue关键字

foreach (ListItem item in cbxlFeatures.Items)
{
  foreach (DataRow row in dt.Rows)
    {
       if (item.Value.Equals(row["Id"].ToString()))
        {
          item.Selected = Convert.ToBoolean(row["Id"]); 
         continue;

        }
         break;
     }
 }
您可以使用关键字continue;如下代码所示

foreach (ListItem item in cbxlFeatures.Items)
{
  foreach (DataRow row in dt.Rows)
    {
       if (item.Value.Equals(row["Id"].ToString()))
        {
          item.Selected = Convert.ToBoolean(row["Id"]); 

          // this is what you need here
          continue;
        }
         break;
     }
 }
如果你有更多的问题,让我知道


感谢Ankur

它实际上是继续,而不是继续。您是想在item==true的内部循环中继续,还是想跳转到下一个复选框,然后忽略以前选中的行?完全正确。。。你难住我了,。。。阿达米:我想,我的问题不清楚。假设我的数据表中有1到10个ID。其中7,8,9的值为false,其余为true。这个id也显示在复选框列表上。只是我的真/假值不同。所以我要求检查条件并将值t/f设置为复选框。一旦复选框设置为选中,循环将跳过。@Amit那么带break的示例代码应该可以工作,那么它怎么会不工作呢?