C# : How to get individual info within Dictionary

Assume : you are coding in C# programming language.

I spent around 2 hours to figuring out “How I can get an individual data from the following chunk of code :

Dictionary<string , object> dict;

Unfortunately , if you use LINQ to figuring out this problem , it would not work ! so , I have one of solutions to share with you by using very simple logic

  1. Set up collection of values of dictionary
  2. foreach true the collection
  3. Set up condition to get what you want
private static object GetIdFromDictionary(IDictionary<string, dynamic> userInfoDict)
{
foreach (var item in userInfoDict)
{
foreach (var i in item.Value)
{
if (i.Key == "Contactid")
{
var returnValue = i.Value;
return returnValue;
}
}
}
return null;
}

Here is a very simple example , I get userInfoDict and then I set collection of the values of this dictionary by item.Value . I want “Contactid” from this dictionary so I set condition checking to get the Contactid value then return it.

Very simple hahhh.

So , if you have any useful solution please tell me and teach me by reply this post .

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.