The simple answer is no, ToList will just loop over the source enumerable and keep the same order.
In LINQ, grouping operators pick the elements of the sequence or collection which contains common attributes and serve them in a group. Or in other words, we can say that the grouping operator returns the group of elements based on the given key.
IEnumerable/IEnumerable<T> makes no guarantees about ordering, but the implementations that use IEnumerable/IEnumerable<T> may or may not guarantee ordering.
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 eachIGrouping<TKey, TElement>
. Elements in a grouping are yielded in the order they appear in source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With