使用LINQ获取一个List <>中的项目,这些项目不在另一个List <>中
我会假设有一个简单的LINQ查询来执行此操作,我只是不确定如何。请参阅下面的代码段。
class Program{ static void Main(string[] args) { List<Person> peopleList1 = new List<Person>(); peopleList1.Add(new Person() { ID = 1 }); peopleList1.Add(new Person() { ID = 2 }); peopleList1.Add(new Person() { ID = 3 }); List<Person> peopleList2 = new List<Person>(); peopleList2.Add(new Person() { ID = 1 }); peopleList2.Add(new Person() { ID = 2 }); peopleList2.Add(new Person() { ID = 3 }); peopleList2.Add(new Person() { ID = 4 }); peopleList2.Add(new Person() { ID = 5 }); }}class Person{ public int ID { get; set; }}
我想执行一个LINQ查询给我所有peopleList2
不在peopleList1
这个例子中的人应该给我两个人(ID = 4&ID = 5)