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 6530475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:45:36+00:00 2026-05-25T09:45:36+00:00

var seller = new User(1); for (var i = 0; i < 3; ++i)

  • 0
var seller = new User(1);

for (var i = 0; i < 3; ++i)
    seller.Children.Add(new User(1));

foreach (var child in seller.Children)
{
    for (var i = 0; i < 3; ++i)
        child.Children.Add(new User(1));

    foreach (var child2 in child.Children)
    {
        for (var i = 0; i < 3; ++i)
            child2.Children.Add(new User(1));

        foreach (var child3 in child2.Children)
            for (var i = 0; i < 3; ++i)
                child3.Children.Add(new User(1));
    }
}

I’m trying to create a tree of objects where each level has 3 objects. I know there’s a way to make this a recursive function

  • 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-25T09:45:36+00:00Added an answer on May 25, 2026 at 9:45 am
    private static void AddChildren(User user, int maxDepth)
    {
        if (maxDepth == 0)
            return;
        for (var i = 0; i < 3; ++i)
        {
            var child = new User(1);
            AddChildren(child, maxDepth - 1);
            user.Children.Add(child);
        }
    }
    

    And the initial call should be

    AddChildren(new User(1), 3); //where 3 is max depth of tree.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var conversations = new Array(); jQuery('.CChatWindow').each(function(){ if (jQuery(this).is(:visible) && jQuery(this).attr(data-conversationid) != 0) { alert(jQuery(this).attr(data-conversationid));
var contentJsonRestStore = new JsonRest({target: myurl}); Trying to implement my rest, but I keep
var ref1 = new Firebase(http://gamma.firebase.com/myuser/123,456); ref1.set(123,456); var on1 = ref1.on(value, function(snapshot) { console.log(snapshot.val()); });
var myOptions_bench = { 1 : '1', 2 : '2', 3 : '3'} $.each(myOptions_bench,
var results = ['one', 'two', 'one hundred', 'three']; var removal = []; $.each(results, function(i)
var queueitem = context.CrawlerQueues. Select(cq => new{cq.Guid,cq.Result}). SingleOrDefault(cq => cq.Guid == guid); Is above
var chart; var d = new Array(); function click() { d = document.getElementById('graph:hi').value; alert(d);
var marker = new google.maps.Marker({ position: myLatlng, map: map, title:Hello World! }); <?php $fd
var longitudeArray = new Array(<?php $result = count($longitudeArray); if ($result > 1){ echo implode(',',
var listOne = new string[] { dog, cat, car, apple}; var listTwo = new

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.