c# LINQ查询分组按
本文关键字:查询 LINQ | 更新日期: 2023-09-27 18:13:52
我刚刚在msdn上看到了这个代码片段:
var studentQuery4 =
from student in students
group student by student.Last[0] into studentGroup
orderby studentGroup.Key
select studentGroup;
学生做什么?去年[0]的意思吗?我们用什么分组?
你的问题中缺少很多信息,但这里是答案:
查询使用学生姓氏的第一个字母作为键对学生进行分组。
其余的文档可以在这里找到:https://msdn.microsoft.com/en-us/library/vstudio/bb397900 (v = vs.110) . aspx
在MSDN页面的第一段中引用示例:
例如,可以根据字符串的首字母对一个字符串序列进行分组。
查询:
var studentQuery4 = from student in students
group student by student.Last[0] into studentGroup
orderby studentGroup.Key
select studentGroup;
按学生姓的首字母分组