Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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]Code block added - OriginalGriff[/edit]
Posted
Updated 3-Jan-12 6:00am
v2

1 solution

Not exactly sure what are the preferred results, but could you use something like:
C#
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
            };
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900