Combining 2 lists and and remove duplicates .Output in a third list .My attempts do not work

后端 未结 4 1077
孤街浪徒
孤街浪徒 2020-12-20 21:32

I always seem to have a problem when I need to compare 2 list and produce a 3rd list which include all unique items.I need to perform this quite often.

Attempt to re

4条回答
  •  离开以前
    2020-12-20 22:34

    Couldn't you do this by using the Concat and Distinct LINQ methods?

    List listOne;
    List listTwo;
    
    List uniqueList = listOne.Concat(listTwo).Distinct().ToList(); 
    

    If necessary, you can use the Distinct() overload that takes an IEqualityComparer to create custom equality comparisons

提交回复
热议问题