我有两个IEnumerable列表。

我想根据第一个列表中的结果将值填充到第二个列表中。

第一个IEnumerable列表是这样填充的:

IEnumerable<SelectListItem> selectedList =
CategoryServices.GetAttributesByCategoryID(categoryID); // it returns selected attributes for a particular category


我有一个函数来获取所有属性。现在,我想获得另一个包含所有其他属性的列表(即,selectedList中不存在的项目)。我尝试了这个:

IEnumerable<SelectListItem> available =
CategoryServices.GetAllAttributes().Where(a => !selectedList.Contains(a));


但是它没有过滤。我拥有所有属性...有什么想法吗?

最佳答案

确保您的SelectListItem类实现了IEquatable<SelectListItem>,因此Contains()方法具有确定实例相等性的适当方法。

10-05 20:44
查看更多