How do you use LINQ to find the duplicate of a specific property?

前端 未结 2 606
长发绾君心
长发绾君心 2021-02-11 19:23
Customer customerOne = new Customer(\"John\", \"Doe\");
Customer customerTwo = new Customer(\"Super\", \"Man\");
Customer customerThree = new Customer(\"Crazy\", \"Guy\"         


        
2条回答
  •  独厮守ぢ
    2021-02-11 19:28

     customers.GroupBy(c => c.LastName).Where(g => g.Skip(1).Any()).SelectMany(c => c)
    

    or with LINQ syntax:

            var q = from c in customers
                    group c by c.LastName into g
                    where g.Skip(1).Any()
                    from c in g
                    select c;
    

提交回复
热议问题