Nested Hashtable

Discussion in 'C#' started by veggieCoder, Nov 3, 2010.

  1. veggieCoder

    veggieCoder New Member

    Joined:
    Aug 20, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I need to parse a hashtable, which contains another nested hashtable. I'm trying to use a foreach to iterate through each DictionaryEntry, but when it gets to the nested hashtable the value is returned as "System.Collections.Hashtable" instead of the hashtable itself. How can I get to the actual nested hashtable?

    Code:
    foreach (DictionaryEntry entry in data)
         {
            Debug.WriteLine(entry.Key + ": " + entry.Value);
          }
    
    The code above returns:

    firstKey: <actual value>
    secondKey: <actual value>
    thirdKey: System.Collections.Hashtable

    Thanks!
     
  2. go4expert

    go4expert Moderator

    Joined:
    Aug 3, 2004
    Messages:
    306
    Likes Received:
    9
    Trophy Points:
    0
    The best way to be doing this is using recursion.

    Have a function that loops through the Hashtable but if you find object is of type list (i.e. Hashtable) instead of normal process call that function once again.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice