Linq实现分组后取最大(小)值

 var beatles = (new[] {
                new { inst = "张三" , age="50" },
                new { inst = "张三" , age="20" },
                new { inst = "何英" , age="35" },
                new { inst = "张三" , age="60" },
                new { inst = "何英" , age="18" }
            });

            var o11 = from d in beatles
                      group d by d.inst into g
                      select new
                      {
                          Id = g.Max(m => m.age),
                          Name = g.Key
                      };
posted @ 2021-09-06 15:57  星畔  阅读(203)  评论(0编辑  收藏  举报