Checking for duplicates in a List of Objects C#

后端 未结 7 745
隐瞒了意图╮
隐瞒了意图╮ 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:11

    If any duplicate occurs throws exception. Dictionary checks keys by itself. this is the easiest way.

    try
    {
      dupList.ToDictionary(a=>new {a.checkThis,a.checkThat});
    }
    catch{
     //message: list items is not uniqe
    }
    

提交回复
热议问题