查询词典列表 [英] Querying a List of Dictionaries

查看:75
本文介绍了查询词典列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个类似下面的字典列表

列表<字典<字符串,字符串> 





我想获取所有具有共同键值对的词典。



Ex。假设我有一个密钥作为客户。我想从列表中获取客户键值为10的所有词典。



预先感谢

Gopi

解决方案

  private  List< Dictionary< string,string>> GetDictionaries(List< Dictionary< string,string>> dictionaries, string 键, string   value ){
List< Dictionary< string,string>> result = new List< Dictionary< string,string>>();
foreach (字典<字符串,字符串> dic 字典){
< span class =code-keyword> if (dic.ContainsKey(key)&& dic [key] .Equals( value )){
result.Add(dic);
}
}
返回结果;
}





这可以让你接近你需要的东西。

希望这有帮助。


Hi
I have a list of Dictionaries something like below

List<Dictionary<string,string>



I would like to fetch all the dictionaries which have a key value pair in common.

Ex. Assume that I have a key as Customer. I would like to fetch all the dictionaries from the list where the customer key has a value of 10.

Thanks in Advance
Gopi

解决方案

private List<Dictionary<string, string>> GetDictionaries(List<Dictionary<string, string>> dictionaries, string key, string value) {
   List<Dictionary<string, string>> result = new List<Dictionary<string, string>>();
   foreach (Dictionary<string, string> dic in dictionaries) {
      if (dic.ContainsKey(key) && dic[key].Equals(value)) {
         result.Add(dic);
      }
   }
   return result;
}



This should get you near what you need.
Hope this helps.


这篇关于查询词典列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆