Group by in LINQ

后端 未结 10 1747
悲哀的现实
悲哀的现实 2020-11-21 06:58

Let\'s suppose if we have a class like:

class Person { 
    internal int PersonID; 
    internal string car; 
}

I have a list of this class

10条回答
  •  春和景丽
    2020-11-21 07:28

    var results = from p in persons
                  group p by p.PersonID into g
                  select new { PersonID = g.Key, Cars = g.Select(m => m.car) };
    

提交回复
热议问题