更新时间:2022-04-15 06:56:48
您可以使用 除外:
List<car> list1 = GetTheList();
List<car> list2 = GetSomeOtherList();
List<car> result = list2.Except(list1).ToList();
您可能甚至不需要那些临时变量:
You probably don't even need those temporary variables:
List<car> result = GetSomeOtherList().Except(GetTheList()).ToList();
请注意,Except
不会修改任何一个列表 - 它会使用结果创建一个新列表.
Note that Except
does not modify either list - it creates a new list with the result.