如果集合发生变化,我可以重启foreach循环吗? [英] Can I restart a foreach loop if collection changes?

查看:87
本文介绍了如果集合发生变化,我可以重启foreach循环吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何重置foreach中的集合,以便在foreach循环中从

读取更改,然后在集合已经更改后重新启动foreach

更改?


foreach(findListBox.listBox2.Items中的字符串发票)

{

listBox2.Items计数已更改,重启此foreach

}


感谢您的帮助。

Trint

-

Trinity Smith

c#/ vb.Net开发商

EcoQuest,Intl。

How can I reset the collections within a foreach to be read as a change from
within the foreach loop then restart the foreach after collections has been
changed?

foreach(string invoice in findListBox.listBox2.Items)
{
listBox2.Items count changed, restart this foreach
}

Thanks for any help.
Trint
--
Trinity Smith
c#/vb.Net Developer
EcoQuest, Intl.

推荐答案

您可以使用break来退出foreach循环。在foreach循环周围,你可以创建一个循环来重启foreach循环。请注意,这是一个挂起您的应用程序的严重线程。也许你应该重新设计


" TrintCSD"写道:
You could use break to exit the foreach loop. Around the foreach loop you
could create a loop to restart the foreach loop. Be aware that this is a
serious thread to hang up your application. Maybe you should redesign

"TrintCSD" wrote:
如何重置foreach中的集合,以便在foreach循环中作为更改从
读取,然后在集合之后重新启动foreach
改变了吗?

foreach(findListBox.listBox2.Items中的字符串发票)
{/> listBox2.Items计数已更改,重启此foreach
}

感谢您的帮助。
Trint
-
Trinity Smith
c#/ vb.Net开发人员
EcoQuest,Intl。
How can I reset the collections within a foreach to be read as a change from
within the foreach loop then restart the foreach after collections has been
changed?

foreach(string invoice in findListBox.listBox2.Items)
{
listBox2.Items count changed, restart this foreach
}

Thanks for any help.
Trint
--
Trinity Smith
c#/vb.Net Developer
EcoQuest, Intl.



这并没有真正告诉我任何事情......我知道如何摆脱循环。什么

你把它放在周围的循环中foreach循环?

谢谢,

Trint

-

Trinity Smith

c#/ vb.Net开发商

EcoQuest,Intl。

" Marinus Holkema"写道:
That doesn''t really tell me anything...I know how to break from a loop. What
kind of loop do you put "around" the foreach loop?
Thanks,
Trint
--
Trinity Smith
c#/vb.Net Developer
EcoQuest, Intl.
"Marinus Holkema" wrote:
你可以使用break来退出foreach循环。在foreach循环周围,你可以创建一个循环来重启foreach循环。请注意,这是一个挂断应用程序的严重线程。也许你应该重新设计

TrintCSD写道:
You could use break to exit the foreach loop. Around the foreach loop you
could create a loop to restart the foreach loop. Be aware that this is a
serious thread to hang up your application. Maybe you should redesign

"TrintCSD" wrote:
如何重置foreach中的集合,以便在foreach循环中作为更改从
读取,然后在集合之后重新启动foreach
改变了吗?

foreach(findListBox.listBox2.Items中的字符串发票)
{/> listBox2.Items计数已更改,重启此foreach
}

感谢您的帮助。
Trint
-
Trinity Smith
c#/ vb.Net开发人员
EcoQuest,Intl。
How can I reset the collections within a foreach to be read as a change from
within the foreach loop then restart the foreach after collections has been
changed?

foreach(string invoice in findListBox.listBox2.Items)
{
listBox2.Items count changed, restart this foreach
}

Thanks for any help.
Trint
--
Trinity Smith
c#/vb.Net Developer
EcoQuest, Intl.



在循环之前将bool标志设置为false


在循环内将标志设置为true,必要时退出循环。


循环后,使用一些机制来测试你是否需要返回并且

重新循环

一种方法是使用


do

{

//循环到这里

} while flag
Set a bool flag before the loop to false

Within the loop set the flag to true, when necessary, and exit the loop.

After the loop, use some mechanism to test whether you need to go back and
re-do the loop
One way is to use

do
{
// loop goes here
} while flag


这篇关于如果集合发生变化,我可以重启foreach循环吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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