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

前端 未结 5 744
走了就别回头了
走了就别回头了 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:52

    You can use .Except() to get the difference between two sets:

    var difference = accessories.Except(foo);
    // difference is now a collection containing elements in accessories that are not in foo
    

    If you then want to add those items to foo:

    foo = foo.Concat(difference).ToList();
    

提交回复
热议问题