按值筛选出字典列表

问题描述 投票:-2回答:3

有没有办法过滤掉使用该值的字典列表?

目前的实施是这样的:

List<Dictionary<string, object>> queue = new List<Dictionary<string, object>>();
//Some code here
queue = queue.Where(x => (string)x[DictionaryKey] != "some Value Here").ToList();

但是这似乎并没有根据传递的值返回过滤后的列表。

c# list dictionary
3个回答
0
投票

要过滤字典,请使用以下条件,x是一个字典,其中您只过滤没有指定值的对。

queue.Where(x => !x.ContainsValue("some Value Her"))

1
投票

我想你正在寻找类似的东西:

queue = queue.Where(x => !x.ContainsValue("some value here")).ToList();

它将返回列表中没有“some value here”值的所有Dictionary对象。


0
投票

你可以随时做到这一点

Foreach(Dictionary item in queue){
    if(item.Keys.Contains("value")){
        queue.Remove(item);
    }
}

可能会奏效

© www.soinside.com 2019 - 2024. All rights reserved.