Remove items from list 1 not in list 2

后端 未结 4 1360
我在风中等你
我在风中等你 2021-02-01 14:32

I am learning to write lambda expressions, and I need help on how to remove all elements from a list which are not in another list.

var list = new List

        
4条回答
  •  甜味超标
    2021-02-01 14:51

    Solution for objects (maybe easier than horaces solution):

    If your list contains objects, rather than scalars, it is that simple, by removing by one selected property of the objects:

        var a = allActivePatientContracts.RemoveAll(x => !allPatients.Select(y => y.Id).Contains(x.PatientId));
    

提交回复
热议问题