请问'的顺序Select`'ing元素有什么不同? [英] Does the order of `Select`'ing elements vary?

查看:118
本文介绍了请问'的顺序Select`'ing元素有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与声明显示对象的工作。

I'm working with an object declared as shown.

DataCollection<Entity> collection = GetDataCollection(...);



然后,我挑选了两套下面的数据。

Then, I'm picking out two sets of data as below.

IEnumerable<String> 
  array_1 = collection.Select(
    element => element.Attributes["attribute_1"] as String),
  array_2 = collection.Select(
    element => element.Attributes["attribute_2"] as String);



我非常好奇,如果这两个阵列保证具有相同的顺序。即如果它们的单独的命令必须是相同的原始序列。或者,最起码,如果订单会以任何理由更改,将 I 日在第单独的列表元素仍然对应日在其他的元素?

I'm terribly curious if those two arrays are guaranteed to have the same order. I.e. if their separate orders must be the same as in the original sequence. Or, at the very least, if the order would change for any reason, will the ith element in the first separate list still correspond to the ith element in the other?

推荐答案

他们不能保证是相同的。在现实中,你可能会注意到,订单通常是与原集合保持一致。

They're not guaranteed to be the same. In reality, you'll probably notice that the order is typically consistent with the original collection.

如果你担心的一致性,只需添加一个排序依据子句,以获得您所需要的顺序(或至少一个是两个结果集之间保持一致)。

If you're worried about consistency, just add an OrderBy clause to get the order you need (or at least one that is consistent between the two resulting collections).

这篇关于请问'的顺序Select`'ing元素有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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