突破Array.ForEach [英] Breaking out of an Array.ForEach

查看:90
本文介绍了突破Array.ForEach的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法突破这样的结构?

If there way to break out of a construct like this?

Array.ForEach(
              properties,
              p =>
                {
                  ListViewItem LVI = DisplayPropertyValue(p);
                  if (LVI.Text != "")
                    aReturn.Add(LVI);
                });



我希望能够设置一个取消"布尔值来放弃它,然后继续进行一些更有趣的事情.我找不到任何地方放置不会给我语法错误的条件.



I''d like to be able to set a "Cancel" bool to abandon it and go on to something more interesting. I can''t find anyplace to put the conditional that doesn''t give me syntax errors.

Another way to do it?

推荐答案

ForEach不是为了这个目的.看起来您可以使用查找"或存在"来执行所需的操作,尽管它们实际上并不是要执行此操作.在这种情况下,最好简单地以旧时尚方式"进行操作,而不要费劲地穿上它.

另一种选择是创建自己的迭代器:
http://msdn.microsoft.com/en-us/magazine/cc163682.aspx [ ^ ]

祝你好运!
The ForEach isn'' t meant for that. It looks like you could use the Find or Exists to do what you want although they aren''t actually meant for that as well. In these situations it is better to simply do it the "old fashion way" instead of shoehorning it in.

Another option is to create your own iterator:
http://msdn.microsoft.com/en-us/magazine/cc163682.aspx[^]

Good luck!


这篇关于突破Array.ForEach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆