可以通过一个foreach循环倒退? [英] Possible to iterate backwards through a foreach?

查看:118
本文介绍了可以通过一个foreach循环倒退?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用语句,并达到同样的效果,但我可以循环向后通过的foreach 循环在C#?

I know I could use a for statement and achieve the same effect, but can I loop backwards through a foreach loop in C#?

推荐答案

在与列表(直接索引),你不能做它作为提高工作效率的使用循环。

When working with a list (direct indexing), you cannot do it as efficiently as using a for loop.

编辑:这通常意味着,当你的能够的使用循环,很可能这个任务的正确方法。此外,对于高达的foreach 正在有序落实,结构本身是专为前pressing循环是独立元素的索引和迭代顺序,这是在并行编程。它的我看来的迭代依靠为了不应该使用的foreach 的循环。

Which generally means, when you are able to use a for loop, it's likely the correct method for this task. Plus, for as much as foreach is implemented in-order, the construct itself is built for expressing loops that are independent of element indexes and iteration order, which is particularly important in parallel programming. It is my opinion that iteration relying on order should not use foreach for looping.

这篇关于可以通过一个foreach循环倒退?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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