How to search for the keys from dictionary of <int, List<string>>

I have dictionary Dictionary<int, List<string>> taskList = new Dictionary<int, List<string>>();

which gives me the out like:

Task ID: 1664003         Values:
                        "2"
                        "5"
                        "1"
                        "4"
                        "3"

Task ID: 1664004         Values:
                        "1"
                        "2"
                        "3"
                        "5"
                        "4"

Task ID: 1664005         Values:
                        "1"
                        "2"
                        "5"
                        "4"
                        "3"

Now I want to search for keys of zero index of pair value like below:

Values: "2"     Task Id: 1664003
Value: "1"      Task Id: 1664004, 1664005

I want to achieve it using lambda expression

>Solution :

class Program
{
   static void Main(string[] args)
   {
      var taskList = new Dictionary<int, List<string>>()
      {
         { 1664003, new List<string>() {"2","5","1","4","3"}},
         { 1664004, new List<string>() {"1","2","3","5","4"}},
         { 1664005, new List<string>() {"1","2","5","4","3"}}
       };

       var list = taskList.ToList();

       var searchKey = "1";

       var keys = list.Where(x=> x.Value[0] == searchKey).Select(x => x.Key).ToList();

       var result = string.Join(",", keys);

   }
}

Leave a Reply