Group by in LINQ

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

    try

    persons.GroupBy(x => x.PersonId).Select(x => x)
    

    or

    to check if any person is repeating in your list try

    persons.GroupBy(x => x.PersonId).Where(x => x.Count() > 1).Any(x => x)
    

提交回复
热议问题