我有一個List< Dictionary < string, object >>
變量,如下所示。在列表中搜索一個值<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);
}
我想搜索鍵,值的字典的列表,並返回List< Dictionary < string, object >>
包含我通過是searchPattern。
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;
}
任何其他建議,搜索也讚賞。 非常感謝!
我不我不明白這個問題。你的例子的預期輸出是什麼? – verdesmarald
你希望返回什麼結果? –
@veredesmarald,@ Cuong Le:在列表中的100行中,我想搜索包含所有鍵值對「aaa」,「aaa4」&「eee」,「eee2」&「fff」的行, 「fff1」和「ddd」,「ddd3」並單獨返回。 –