Remove elements from one List that are found in another

后端 未结 8 1077
情话喂你
情话喂你 2020-12-10 11:31

I have two lists

 List list1 = new List();
 List list2 = new List();

I want remove all elements from li

8条回答
  •  再見小時候
    2020-12-10 11:54

    If you want to remove a list of objects (list2) from another list (list1) use:

    list1 = list1.Except(list2).ToList()
    

    Remember to use ToList() to convert IEnumerable to List.

提交回复
热议问题