Linq to Objects:GroupBy 是否保留元素的顺序? [英] Linq to Objects: does GroupBy preserve order of elements?
本文介绍了Linq to Objects:GroupBy 是否保留元素的顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从 LINQ to Objects 的 Enumerable.GroupBy 是否保留组中元素的顺序?
Does Enumerable.GroupBy from LINQ to Objects preserve order of elements in the groups?
推荐答案
在 MSDN:是的.
IGrouping
对象是根据产生每个 IGrouping
代码>.分组中的元素按照它们在源中出现的顺序产生.
The
IGrouping<TKey, TElement>
objects are yielded in an order based on the order of the elements in source that produced the first key of eachIGrouping<TKey, TElement>
. Elements in a grouping are yielded in the order they appear in source.
这篇关于Linq to Objects:GroupBy 是否保留元素的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文