是对象的顺序返回FOREACH稳定吗? [英] Is the order of objects returned by FOREACH stable?

查看:181
本文介绍了是对象的顺序返回FOREACH稳定吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是安全的假设两个itterations在相同的集合将返回对象以相同的顺序?显然,假设集合工作尚未改变。

Is it safe to assume that two itterations over the same collection will return the objects in the same order? Obviously, it is assumed that the collection has not otherwise been changed.

推荐答案

简短的回答 - 是的,

Short answer - yes.

显然,虽然,这两个项目集合中的顺序可能不完全,因为它们被插入,这取决于集合的类型(一个字典,例如)。

Obviously, though, the order of the items in the collection may not be exactly as they were inserted, depending on the type of collection (a dictionary, for example).

但你会使用foreach循环每次迭代一个单一的,未经修改的收集时间得到相同的结果。

But you will get the same results each time you iterate over a single, unmodified collection using a foreach loop.

这篇关于是对象的顺序返回FOREACH稳定吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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