c# - .GroupBy() 是否保证其分组的顺序?

标签 c# linq group-by linq-to-objects ilookup

假设我有一个(有序的)动物序列:

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/

相关文章:

mysql - 使用 GROUP BY 获取单个值 - MySQL

c# - 自定义事件处理程序

c# - LINQ:将多个属性的对象列表分组到列表列表中的更好方法?

c# - 通过System.Linq在C#中获取元素的属性名称和值

python - 每 6 小时对数据帧进行分组并生成一个新列

Mysql 按多个具有不同值的列进行分组

c# - 如何使用基于按位枚举的参数从 Entity Framework 返回值

c# - Web Config.Connection String 中的相对路径引用

c# - 对下面的应用程序进行表单点击 "fall through"

c# - 如何在 C# 中使用 lambda 表达式进行嵌套 where 查询