如何比较对象的2列出并删除不常见的项目? [英] How to compare 2 lists of objects and remove the items that are not common?
问题描述
我有2不包含相同类型的所有领域泛型列表
I've got 2 generic lists that do not contain the all fields of the same type
IList<Category> and List<CategoriesRow>Categories
categoryList = IList<Category>
但两者有共同的字段名称和ID。
but both have common fields Name and ID.
我想比较所属分类列表分类,并找到那些来自哪里所属分类所属分类[指数] .ID不ID的所有类别列表中存在。对于所有那些不分类存在,我必须从CatgoryList删除它们。
I want to compare list Categories with categoryList and find those from categoryList where categoryList[index].ID does not exist in the list of all Categories of ID. For all those that do not exist in Categories, I will have to remove them from CatgoryList.
我以前的帖子中,我得到了LINQ的例子,但问题是,我必须使用动态,这意味着我传递所属分类和类别的动态。
I had a previous post in which I was given examples of LINQ, but the problem is I have to use Dynamic, implying that I am passing categoryList and Categories as Dynamic.
谁能给我一个例子,如何去了解上面的这些我都没有知道如何做到这一点。
Can anyone give me an example how to go about the above as I have no idea how to do it.
推荐答案
使用。除
LINQ运营商
这样的:
var uniqueList = list1.Except(list2);
不知道你的我必须使用动态的意思。
Not sure what you mean by "I have to use Dynamic".
这是可用于实现的IEnumerable
各类标准的LINQ操作。
This is a standard LINQ operation available to all types that implement IEnumerable
.
这里的上做的好文章。
这篇关于如何比较对象的2列出并删除不常见的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!