Get Non-Distinct elements from an IEnumerable

前端 未结 4 1468
心在旅途
心在旅途 2021-02-13 13:18

I have a class called Item. Item has an identifier property called ItemCode which is a string. I would like to get a list of all non-distinct Items in a list of Items.

E

4条回答
  •  鱼传尺愫
    2021-02-13 14:08

    My take:

    var distinctItems = 
        from list in itemsList
        group list by list.ItemCode into grouped
        where grouped.Count() > 1
        select grouped;
    

提交回复
热议问题