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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -