gpt4 book ai didi

c# - 基于另一个列表过滤列表 - LINQ

转载 作者:太空宇宙 更新时间:2023-11-03 22:08:17 24 4
gpt4 key购买 nike

我有两个 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类(class)工具 IEquatable<SelectListItem> 所以 Contains()方法具有确定实例相等性的适当方法。

关于c# - 基于另一个列表过滤列表 - LINQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7622167/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com