【发布时间】:2012-09-06 02:59:49
【问题描述】:
我有一个List< Dictionary < string, object >> 变量,如下所示。
private static List<Dictionary<string, object>> testData = new List<Dictionary<string, object>>(100);
// Just Sample data for understanding.
for (int i = 0; i < 100; i++)
{
var test = new Dictionary<string, object>
{
{ "aaa", "aaa" + i % 4 },
{ "bbb", "bbb" + i % 4 },
{ "ccc", "ccc" + i % 4 },
{ "ddd", "ddd" + i % 4 },
{ "eee", "eee" + i % 4 },
{ "fff", "fff" + i % 4 },
{ "ggg", "ggg" + i % 4 },
{ "hhh", "hhh" + i % 4 },
{ "iii", "iii" + i % 4 }
};
testData.Add(test);
}
我想在 Dictionary 中搜索 key、value 列表并返回包含我传递的 searchPattern 的 List< Dictionary < string, object >>。
Dictionary<string, object> searchPattern = new Dictionary<string, object>();
searchPattern .Add("aaa", "aaa4");
searchPattern .Add("eee", "eee2");
searchPattern .Add("fff", "fff1");
searchPattern .Add("ddd", "ddd3");
public List<Dictionary<string, object>> SearchList(List<Dictionary<string, object>> testData, Dictionary<string, object> searchPattern)
{
List<Dictionary<string, object>> result;
// Search the list.
return result;
}
任何其他搜索建议也很感激。 非常感谢!!
【问题讨论】:
-
我不明白这个问题。您的示例的预期输出是什么?
-
你期望返回什么结果?
-
@veredesmarald, @Cuong Le:在列表的 100 行中,我想搜索包含所有键值对“aaa”、“aaa4”和“eee”的行eee2" & "fff", "fff1" & "ddd", "ddd3" 并单独返回。
-
您的测试数据中的字典都不包含所有这些键值对。
-
当我看到这样的东西时,我想,嗯,这是可行的,但我感觉你一开始就做错了什么。
标签: c# list search .net-4.0 dictionary