Find all intersecting data, not just the unique values

前端 未结 4 472
孤城傲影
孤城傲影 2021-01-11 13:52

I thought that I understood Intersect, but it turns out I was wrong.

 List list1 = new List() { 1, 2, 3, 2, 3};
 List<         


        
4条回答
  •  清歌不尽
    2021-01-11 14:15

    var set = new HashSet(list1.Intersect(list2));
    return list1.Concat(list2).Where(i=>set.Contains(i));
    

提交回复
热议问题