你能以相反的顺序运行foreach吗? [英] Can you run a foreach in reverse order?
问题描述
是否可以执行类似于STL迭代器的操作,即以相反的顺序执行$ b $ ba foreach循环?
谢谢,
Fabio
Is it possible to do something similar to the STL iterators, i.e. to execute
a foreach loop in reverse order?
Thanks,
Fabio
推荐答案
在这里讨论......
http://groups.google.com/group/微... e1478a9703dd2d
Discussed here......
http://groups.google.com/group/micro...e1478a9703dd2d
Fabio,
Fabio,
是否有可能做类似的事情STL迭代器,即以相反的顺序执行foreach循环?
Is it possible to do something similar to the STL iterators, i.e. to
execute a foreach loop in reverse order?
在执行
之前,可以简单地颠倒集合的顺序
foreach循环。我知道这是第二好的选择。然而,它会起作用。
问候,
兰迪
One could simply reverse the order of the collection before executing the
foreach loop. I know that is a second-best options. However, it will work.
Regards,
Randy
Fabio Cannizzo < FC ***************** @ london.edu>写道:
Fabio Cannizzo <fc*****************@london.edu> wrote:
是否有可能做类似于STL迭代器的事情,即以相反的顺序执行一个foreach循环?
Is it possible to do something similar to the STL iterators, i.e. to execute
a foreach loop in reverse order?
否 - 并不是每个迭代器都能支持这种行为
无论如何。考虑一个基于来自
a网络的流的foreach - 你必须等待才能找到流的结尾(如果那个
曾经发生过)在你开始回馈数字之前。
另一个例子 - 考虑一个产生素数的迭代器,在
顺序中。反转迭代器会做什么?
-
Jon Skeet - < sk *** @ pobox.com>
如果回复小组,请不要给我发邮件
No - and not every iterator would be able to support that behaviour
anyway. Consider a foreach which was based off a stream coming in from
a network - you''d have to wait to find the end of the stream (if that
ever happened) before you could start giving back numbers.
Another example - consider an iterator which yielded prime numbers, in
order. What would a reversed iterator do?
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
这篇关于你能以相反的顺序运行foreach吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!