Find if listA contains any elements not in listB

后端 未结 7 728
春和景丽
春和景丽 2020-11-30 03:25

I have two lists:

List listA     
List listB

How to check using LINQ if in the listA exists an element w

7条回答
  •  心在旅途
    2020-11-30 04:25

    Get the difference of two lists using Any(). The Linq Any() function returns a boolean if a condition is met but you can use it to return the difference of two lists:

    var difference = ListA.Where(a => !ListB.Any(b => b.ListItem == a.ListItem)).ToList();
    

提交回复
热议问题