LINQ - Find all items in one list that aren't in another list

前端 未结 3 1060
一个人的身影
一个人的身影 2020-12-28 12:01

I\'m stuck with a LINQ query (or any other efficient means of accomplishing the same thing). Can someone show me how I can select all the items in one list that are not pre

相关标签:
3条回答
  • 2020-12-28 12:28

    Try using .Except extension method (docs):

    var result = list1.Except(list2);
    

    will give you all items in list1 that are not in list2.

    0 讨论(0)
  • 2020-12-28 12:38

    The easiest way is to use the Except method.

    var deletedItems = list1.Except(joinItems);
    

    This will return the set of items in list1 that's not contained in joinItems

    0 讨论(0)
  • 2020-12-28 12:45

    Try this:

    var List2 = OriginalList.Where(item => !List1.Any(item2 => item2.ID == item.ID));
    
    0 讨论(0)
提交回复
热议问题