对数组列表项使用LINQ Where

oknrviil  于 2023-01-10  发布在  其他
关注(0)|答案(1)|浏览(174)

有人能帮我吗?我怎样才能获得arrayList中的所有appsRelatedIds?我在API集成方面工作,我有类Apps:

public class Apps
    {
        [JsonProperty("id")]
        public string Id { get; set; }
 
        [JsonProperty("active")]
        public bool Active { get; set; }

        [JsonProperty("description")]
        public string Description { get; set; }
        
        [JsonProperty("appsRelatedIds")]
        public ArrayList RelatedId { get; set; }

   }

我已经创建了这个LINQ并且运行良好:

var appsFiltered = AppsList.Where(x => x.Active == true && x.Description.Contains("Top")).ToList();

但我需要通过RelatedIds获取,例如,对于此响应,API仅返回相关的ID:

int relatedId = 5;  
var appsFiltered = AppsList.Where(x => x.Active == true && x.RelatedId.Contains(relatedId).ToList();

示例数据:

  1. line1-Id 1234活动= true描述="顶级枪手"相关Id =[1,2,3,4,5]
    1.第2行-Id 12345活动= true描述='顶级枪手'特立独行'相关Id =[1,3,4,5]
    1.第3行-Id 123456活动=真描述="变压器"相关Id =[7,8,9]
    在本例中,我需要使用第1行和第2行进行appsFiltered,因为relatedId参数5位于RelatedId ArrayList中。
    我试着用LINQ
yuvru6vn

yuvru6vn1#

为什么使用ArrayList而不是List?ArrayList通常性能很低

var appsFiltered = AppsList.Where(x => x.Active == true && x.RelatedId.Any(a=> a == relatedId).ToList();

相关问题