c# - How to get key value based on id from list of dictionaries? -


this code

public class model  {     public model();     public list<dictionary<string, string>> data { get; set; } }  list<dictionary<string,string>> data1;  var data1 = await get<model>();  data1[0]=[0][{id,101}]          [1][{name,one}]  data1[1]=[0][{id,102}]          [1][{name,two}]  data1[2]=[0][{id,103}]          [1][{name,three}] 

in code have list of dictionaries id , name keys. have id=102 search in list of dictionaries , name value related on id using linq query.

var name = data1.first(d => d["id"] == "102")["name"]; 

you find first list element key "id" maps value "102", , value key "name".


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -