C# – while循环中的foreach循环 – 打破foreach并立即继续while循环?

while (foo() == true)
{
   foreach (var x in xs)
   {
       if (bar(x) == true)
       {
           //"break;" out of this foreach
           //AND "continue;" on the while loop.
       }
   }

   //If I didn't continue,do other stuff.
}

我有点坚持如何做到这一点.

更新:我修正了问题.我遗漏了一个事实,即如果我不打电话给继续,我需要处理其他事情;在while循环中.

对不起,我没有意识到我曾两次使用“某事”这个词.

解决方法

如果我理解正确,您可以在此处使用LINQ Any/ All谓词:
while (something)
{
    // You can also write this with the Enumerable.All method
   if(!xs.Any(x => somePredicate(x))
   {
      // Place code meant for the "If I didn't continue,do other stuff."
      // block here.
   }
}

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...