var list = new List<Course>() { new Course(1,"art"), new Course(2,"art"), new Course(3,"history"), new Course(1,"history"), new Course(3,"physics") }; var res=list.GroupBy(x => x.stId).Select(x => new { x.Key, names = x.AsEnumerable().Select(g=>g.CourseName).ToArray() }).ToList();
实现效果如下图