.GroupBy()是否保证其分组中的订单? [英] Does .GroupBy() guarantee order in its groupings?
本文介绍了.GroupBy()是否保证其分组中的订单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Eagle
大象
塔兰图拉
玳瑁
老虎
和我的第一个字母组合:
<$ ps.p>
Animals.GroupBy(animal => animal.First())
结果序列中的 IGrouping
s的元素与输入序列的顺序是否一样?
解决方案
是的,他们将是: GroupBy(MSDN )。
IGrouping< TKey,TElement>对象是根据源中元素的顺序这产生了每个IGrouping< TKey,TElement>的第一个关键字。
在分组中的元素按照它们出现在源代码中的顺序出现。
Say I have an (ordered) sequence of animals:
Eagle Elephant Tarantula Terrapin Tiger
and I group by first letter:
Animals.GroupBy(animal => animal.First())
will the elements of the IGrouping
s in the resulting sequence be in the same order as the input sequence?
解决方案
Yes, they will be: GroupBy (MSDN).
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 each IGrouping<TKey, TElement>. Elements in a grouping are yielded in the order they appear in source.
这篇关于.GroupBy()是否保证其分组中的订单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文