Konstantin Spirin
Konstantin Spirin

Reputation: 21321

Linq to Objects: does GroupBy preserve order of elements?

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

Upvotes: 143

Views: 18887

Answers (1)

Konstantin Spirin
Konstantin Spirin

Reputation: 21321

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.

Upvotes: 202

Related Questions