How to access a hashtable inside another hashtable?
I have 2 hashtables:h1 and h2..
Here I require to use a hashtable within another hashtable..
Something like the following:
Code:
foreach(DictionaryEntry entry in h1)
{
/*some operation*/
foreach(DictionaryEntry entry1 in h2)
{
/*processing*/
}
}
But it results in an unexpected exception..
How can I do it??
Re: How to access a hashtable inside another hashtable?
Is there any other way to access the contents of the hashtable without using foreach loop??
Re: How to access a hashtable inside another hashtable?
The code you've shown doesn't give us enough detail to work with. Also, you didn't mention the error you are getting.
Please give us a more complete code snippet and also specify what exception you are getting.
Re: How to access a hashtable inside another hashtable?
Well where does h2 come from? If you have a nested dictionary and you want to iterate over the nested one it should be:
Code:
// I have to guess as to what your key is, so I chose int and A,B
var nestedDict = new Dictionary<int, Dictionary<A,B>>();
// populate dictionary
foreach(var dict in nestedDict.Values)
{
// 'dict' is a Dictionary<A,B>
}