How to compare 2 List objects to get the missing value from the List

前端 未结 5 679
走了就别回头了
走了就别回头了 2021-01-27 02:23

How do I use the \"NOT IN\" to get the missing data, to be added to \"foo\" List.

var accessories = new List(); 
var foo = new List()         


        
5条回答
  •  遥遥无期
    2021-01-27 02:41

    You can combine Concat and Distinct to do this:

    foo = foo.Concat(accessories).Distinct().ToList();
    

    Edit: Or Except as others have pointed out, which seems to be the superior choice for this case.

提交回复
热议问题