Checking for duplicates in a List of Objects C#

后端 未结 7 721
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 20:35

I am looking for a really fast way to check for duplicates in a list of objects.

I was thinking of simply looping through the list and doing a manual comparison th

7条回答
  •  温柔的废话
    2020-12-29 21:18

    Do a select distinct with linq, e.g. How can I do SELECT UNIQUE with LINQ?

    And then compare counts of the distinct results with the non-distinct results. That will give you a boolean saying if the list has doubles.

    Also, you could try using a Dictionary, which will guarantee the key is unique.

提交回复
热议问题