Click here to Skip to main content
15,940,246 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i have a dictionary which contain the key as a string and value as the list
so how to get the value od particular key
and i want to replace certatin string from that value which is as a list.
Posted

If you mean you have this:
C#
Dictionary<string, List<string>> myDict = ...
then its relatively easy:
C#
List<string> values = myDict["my key"];
values[2] = "new value string";
Or
C#
myDict["my Key"][2] = "new value string";
 
Share this answer
 
Comments
rahuls1 21-Jan-14 7:11am    
i want to get the value of the key..
OriginalGriff 21-Jan-14 7:14am    
Sorry? I don't understand you.
Normally you use the dictionary key to find the value: do you want a list of all the keys? Or are you trying to find a key from a value?
rahuls1 21-Jan-14 7:21am    
i want to find Value from Key and My value is a list..
OriginalGriff 21-Jan-14 7:24am    
If you have a the key, then just use it as in my first example: the key is the string "my key" and it fetches the List of strings associated with the key into the "values" variable.
Try this


C#
Dictionary<string, List<string>> dict = new Dictionary<string, List<string>>();
            dict.Add("one", new string[] { "aaa", "bb", "nnn", "dd" }.ToList());
            dict.Add("two", new string[] { "d", "bb", "cc", "uuu" }.ToList());
            dict.Add("three", new string[] { "affaa", "bb", "cc", "gggdd" }.ToList());
            dict.Add("four", new string[] { "adfdaa", "xxbb", "ccg", "dd" }.ToList());

            string key = "one";
           List<string> Value =  dict[key];
           string replacefrom = "aaa";
           string replaceTo = "apple";
           Value[Value.IndexOf(replacefrom)] = replaceTo;

now the dictionary will be updated with the new item, since it is a reference Type
 
Share this answer
 
Comments
rahuls1 21-Jan-14 7:23am    
please read above commnent and reply..
Karthik_Mahalingam 21-Jan-14 8:00am    
Value will be having the list ..
what u need ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900