Linq to Objects: does GroupBy preserve order of elements?

前端 未结 1 505
感情败类
感情败类 2020-12-03 02:31

Does Enumerable.GroupBy from LINQ to Objects preserve order of elements in the groups?

相关标签:
1条回答
  • 2020-12-03 03:05

    Found answer on MSDN: Yes.

    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.

    0 讨论(0)
提交回复
热议问题