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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:52:01+00:00 2026-06-15T01:52:01+00:00

I have a problem with a List of objects … This List contains objects

  • 0

I have a problem with a List of objects …

This List contains objects which themselves contain objects, and so on … (all objects are of the same type)

My objects looks like that :

  public class MyObject (...)
  {
    ...
    public MyObject[] Object;
    ...
  }

I’d like to change some variables of these objects (according to certain parameters), and to do that I think using LINQ.

My problem is that I do not really know how to do something that will pass through ALL my recursive List, regardless of their level.

I hope I was as clear as possible.

Thank you in advance for your help.

  • 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-06-15T01:52:02+00:00Added an answer on June 15, 2026 at 1:52 am

    You can write a simple recursive method to do what you want easily enough:

    public static void Touch(MyObject obj, string otherParameter)
    {
        obj.Value = otherParameter;
        foreach (var child in obj.Object)
        {
            Touch(child, otherParameter);
        }
    }
    

    If you really, really want a more LINQ-esque method, or you do this often enough to need a more generic approach, you could use something like this:

    public static IEnumerable<T> FlattenTree<T>(IEnumerable<T> source, Func<T, IEnumerable<T>> selector)
    {
        //you could change this to a Queue or any other data structure 
        //to change the type of traversal from depth first to breath first or whatever
        var stack = new Stack<T>(); 
        while (stack.Any())
        {
            T next = stack.Pop();
            yield return next;
            foreach (T child in selector(next))
                stack.Push(child);
        }
    }
    

    You could then use it like:

    MyObject root = new MyObject();
    
    var allNodes = FlattenTree(new[] { root }, node => node.Object);
    foreach (var node in allNodes)
    {
        node.Value = "value";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I have a document class which contains a list of objects. These objects
I have a list of objects MyObject and that looks like this: var Obj1
The problem is: I have a list of objects, with some containing the same
I have a list that contains many objects.I want found an object in this
I have a list of objects, of which I cannot know the type of
The problem I have is this: I have one GridView with a list objects
The problem: I have a list of objects which have Date, Name, and Value
I'm having a problem. I have the list of JSON objects in a separate
I have a class that contains a static number of objects. This class needs
I have a problem with deleting my objects. I wrote a delete method which

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.