Remove items from list that intersect on property using Linq

前端 未结 2 648
滥情空心
滥情空心 2021-02-12 15:24

I have 2 lists of different objects (foo & bar) that share the same property lets call it id.

public List          


        
2条回答
  •  灰色年华
    2021-02-12 16:07

    var foo = foo.Where(f => !bar.Any(b => b.Id == f.Id)).ToList();
    

    Just keep in mind that this is a O(n²) solution, it won't work very well for big lists.

提交回复
热议问题