CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2012
    Posts
    18

    Question 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??

  2. #2
    Join Date
    Jan 2012
    Posts
    18

    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??

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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.

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    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>
    }
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured