用字典查找列表的值 [英] find values of a list with a dictionary

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

问题描述

我正在尝试查找列表中包含值的字典行.并且列表中的值等于某个值;
语法让我发疯-任何指针

I am trying to find row of a dictionary where the values are in the list. and the the values in the list are equel to some value;
The syntax is driving me crazy -- any pointers

namespace ConsoleApplication1
{
    internal class Program
    {
        private static void Main(string[] args)
        {

            Dictionary<string,>> namesInfo = new Dictionary<string,>>()
                                                          {
                                                              {"howard", new List<int> {{5}, {5}, {2}, {4}}},
                                                              {"John", new List<int>{{1},{2},{3},{5}}}

                                                          };

            var list4 = from l in namesInfo
                        from nums in l.Value
                        where l.Value = 4 
                        select new
                                   {
                                      l.Key
                                   }
                      
        }
    }
}



[edit]已添加代码块-OriginalGriff [/edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

不确定确切的首选结果是什么,但是可以使用类似的方法:
Not exactly sure what are the preferred results, but could you use something like:
Dictionary<string,List<int>> namesInfo 
   = new Dictionary<string,List<int>>() {
       {"howard", new List<int> {{5}, {5}, {2}, {4}}},
       {"John", new List<int>{{1},{2},{3},{5}}}
   };

var list4 = from l in namesInfo.Where(a=>a.Value.Contains(4))
            select new {
               l.Key
            };


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

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