C# 3.0: Need to return duplicates from a List<>

前端 未结 8 1869
无人及你
无人及你 2020-12-23 19:05

I have a List<> of objects in C# and I need a way to return those objects that are considered duplicates within the list. I do not need the Distinct resultset, I need a

8条回答
  •  醉梦人生
    2020-12-23 19:38

    Without actually coding it, how about an algorithm something like this:

    • iterate through your List creating a Dictionary
    • iterate through your Dictionary deleting entries where the int is >1

    Anything left in the Dictionary has duplicates. The second part where you actually delete is optional, of course. You can just iterate through the Dictionary and look for the >1's to take action.

    EDIT: OK, I bumped up Ryan's since he actually gave you code. ;)

提交回复
热议问题