假设我有一个(有序的)动物序列:
Eagle Elephant Tarantula Terrapin Tiger
and I group by first letter:
Animals.GroupBy(animal => animal.First())
结果序列中的IGrouping
元素的顺序是否与输入序列相同?
最佳答案
是的,它们将是: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.
关于c# - .GroupBy() 是否保证其分组的顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12377891/