Ways of getting values from Dictionaries.

Rajesh_Kumar
Posted by Rajesh_Kumar under ASP.NET category on | Points: 40 | Views : 2245
Dictionary<int,string> dict_names = new Dictionary<int,string>();
dict_names.Add("n]ame","rajesh");
dict_names.Add("surname","sathua");

1st way:-
int value1 = dict_names["name"]; //output will be rajesh
int value2 = dict_names["surname"]; //output will be sathua

2nd way:-
foreach(KeyValuePair<int,string> pair in dict_names)
{
Response.Write(pair.Key + ":" + pair.Value);
}

Comments or Responses

Login to post response