Retrieve c# Dictionary value type -


i have dictionary of string(key) , object(value). how can type of each value in dictionary?

sample code:

dictionary<string, object> jsondata; arraylist arr =  new arraylist();  arr.add("1"); arr.add("2");     arr.add("3");  jsondata["status"] = "200"; jsondata["data"] = arr;   foreach(keyvaluepair<string, object> item in jsondata) {      item.value          //  type string vs arraylist ?? } 

you try-cast value these types as-operator:

foreach(keyvaluepair<string, object> item in jsondata) {     arraylist list;     string str;     if ((list = item.value arraylist) != null)     {       }     else if ((str = item.value string) != null)     {       } } 

another way use is-operator:

foreach(keyvaluepair<string, object> item in jsondata) {     if (item.value arraylist)     {          arraylist list = (arraylist) item.value;     }     else if (item.value string)     {          string str = (string) item.value;     } } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -