Group by in LINQ

后端 未结 10 1606
悲哀的现实
悲哀的现实 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:34

    You can also Try this:

    var results= persons.GroupBy(n => new { n.PersonId, n.car})
                    .Select(g => new {
                                   g.Key.PersonId,
                                   g.Key.car)}).ToList();
    

提交回复
热议问题