Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1092333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:39:58+00:00 2026-05-16T23:39:58+00:00

And there could be many levels, who knows how deep it could go! Also

  • 0

And there could be many levels, who knows how deep it could go! Also let’s say for this specific question that the String for another Dictionary will be “Dictionary” and a value that I want to access/modify will be “Data”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:39:58+00:00Added an answer on May 16, 2026 at 11:39 pm

    Will I need a recursive function to iterate through a Dictionary<String, Object> of Dictionary<String, Object>s?

    No. Any recursive algorithm can be rewritten to use an explicit stack rather than the call stack.

    Is it easier to use recursion to do so?

    Perhaps. However, if the structure is very deeply nested (or contains cycles) you can run the risk of a stack overflow exception.

    The non-recursive implementation is not particularly hard to implement. It would require you to maintain a list (a stack or queue, depending on what order you want to visit children in) that keeps track of the sub-dictionaries yet to be visited.

    A prototypical (non-recursive) implementation would look something like:

    public IEnumerable<string> GetAllKeys( Dictionary<string,object> dictionary )
    {
        var stackDictionariesToVisit = new Stack<Dictionary<string,object>>();
    
        stackDictionariesToVisit.Push( dictionary );
    
        // keep visiting iterating until the stack of dictionaries to visit is empty
        while( stackDictionariesToVisit.Count > 0 )
        {
            var nextDictionary = stackDictionariesToVisit.Pop();
            foreach( var keyValuePair in nextDictionary )
            {
                if( keyValuePair.Value is Dictionary<string,object> )
                {
                    stackDictionariesToVisit.Push( 
                         keyValuePair.Value as Dictionary<string,object> );
                }
                else
                {
                    yield return keyValuePair.Key;
                }
            }
        }
    }
    

    The implementation above does no error checking and it doesn’t check for cycles, but it replaces recursion with an explicit stack.

    The choice of whether to use recursion (or not) for visiting a hierarchical data structure should depend on an understanding of the kind of data being stored rather than which approach is easier. If you have a deeply nested structure, you are better off NOT using recursion since you can’t control how much stack space you’ll have available. On the other hand, if you are confident that the data will never nest more than a few level, a recursive implementation may be (slightly) easier to understand and maintain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now there is a subject that could be taken many ways. Hopefully I will
Is there a method that could tell for a string like foo bar Foo
Are there any security exploits that could occur in this scenario: eval(repr(unsanitized_user_input), {__builtins__: None},
Is there any way that I could enjoy a decodeValue() function in PHP, too?
Not getting into too many specifics, this is a high level question. I've always
I have a url which could be www.website.com/order/?pg3=2 or www.website.com/orderstatus/?pg2= There could be several
Are there tools out there which could automatically find copy-and-paste code among a set
Is there anything I could do to get my own open source stuff into
Is there a way could i delete my application from some users iPhone by
Is there any way I could run the following 'logical code' to actually work?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.