Remove duplicates from a List in C#

前端 未结 27 1759
广开言路
广开言路 2020-11-22 04:41

Anyone have a quick method for de-duplicating a generic List in C#?

27条回答
  •  旧巷少年郎
    2020-11-22 05:18

    Might be easier to simply make sure that duplicates are not added to the list.

    if(items.IndexOf(new_item) < 0) 
        items.add(new_item)
    

提交回复
热议问题