Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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);

   }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading