LINQ's Distinct() on a particular property

后端 未结 20 2569
一向
一向 2020-11-21 05:05

I am playing with LINQ to learn about it, but I can\'t figure out how to use Distinct when I do not have a simple list (a simple list of integers is pretty easy

20条回答
  •  深忆病人
    2020-11-21 05:43

    You could also use query syntax if you want it to look all LINQ-like:

    var uniquePeople = from p in people
                       group p by new {p.ID} //or group by new {p.ID, p.Name, p.Whatever}
                       into mygroup
                       select mygroup.FirstOrDefault();
    

提交回复
热议问题