LINQ - Distinct by value?

后端 未结 5 1052
醉话见心
醉话见心 2021-01-12 17:00

Code :

news = (from New myNew in new News()
       select myNew).Distinct().ToList();

but this Distinct is for \"object\" with same values.

5条回答
  •  长情又很酷
    2021-01-12 17:20

    Short hand solution

    var vNews  =  News()   
                  .GroupBy(p => p.Month, (key, p) => p.FirstOrDefault()) 
                  .ToList();
    

提交回复
热议问题