I have a dictionary < string,object > which has a mapping of a string and a dictionary < string,int >. How do I add a key value pair in the inside dictionary < string ,int > ?
Dictionary <string,object> dict = new Dictionary <string,object>();
Dictionary <string,int> insideDict = new Dictionary <string,int>();
// ad some values in insideDict
dict.Add("blah",insideDict);
So now the dict has a dictionary mapped with a string.Now I want to separately add values to the insideDict. I tried
dict["blah"].Add();
Where am I going wrong?
Replace the TValue with your value type.
Something like below
(OR) if you already have defined the inner dictionary then
Per your comment tried this but screwed up somewhere
You didn't got it cause of your below line where you forgot to cast the inner dictionary value to
Dictionary<string, int>
since your outer dictionary value isobject
. You should rather have your outer dictionary declared strongly typed.Do you mean something like this?