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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:11:42+00:00 2026-06-17T14:11:42+00:00

I am trying to create a class that contains a list of items within

  • 0

I am trying to create a class that contains a list of “items” within it. Which I have successfully done, however then I would like to create a list of items within the list of items. I have also been able to do this however I had to use a different name for the class within the item.

I would like to use the same class name as this will be used to generate some json where the class name is important. In addition I would like to be able to do this in a way where it could be recursive like a folder structure. All the properties would be the same for each. I hope I am explaining this well enough. I am essentially trying to create a folder / file structure where there can be x number of files in each folder that can also have x number of folders and so forth.

For example:

DocLib

-Item

–Item.Items

—Item.Items.Items

–Item.Items

-Item 2 etc…

Here is the existing code:

public class DocLib
{
    public string Title { get; set; }
    public string spriteCssClass { get { return "rootfolder"; } }
    public List<item> items { get; set; }

    public DocLib()
    {
        items = new List<item>();
    }

    public class item
    {
        public string Title { get; set; }
        public string spriteCssClass { get; set; }
        public List<document> documents { get; set; }

        public item()
        {
            documents = new List<document>();
        }

        public class document
        {
            public string Title { get; set; }
            public string spriteCssClass { get; set; }
        }
    }
}

I am sure there is probably a better way of implementing this.

  • 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-17T14:11:43+00:00Added an answer on June 17, 2026 at 2:11 pm

    Just let items be a list of your “own” type

    public class DocLib{
       public string Title { get; set; }
       public string spriteCssClass { get { return "rootfolder"; } }
    
       List<DocLib> _items;
    
       public DocLib(){
          _items = new List<DocLib>();
       }
    
       public List<DocLib> Items { 
          get{
             return _items;
          }
       }
    }
    

    EDIT usage sample:

    public static class DocLibExtensions {
        public static void Traverse(this DocLib lib,Action<DocLib> process) {
            foreach (var item in lib.Items) {
                process(item);
                item.Traverse(process);
            }
        }
    }
    
    class Program {
        static void Main(string[] args) {
    
            DocLib rootDoc = new DocLib {Title = "root"};
    
            rootDoc.Items.Add( new DocLib{ Title = "c1" });
            rootDoc.Items.Add(new DocLib { Title = "c2" });
    
            DocLib child = new DocLib {Title = "c3"};
            child.Items.Add(new DocLib {Title = "c3.1"});
    
            rootDoc.Items.Add(child);
    
            rootDoc.Traverse(i => Console.WriteLine(i.Title));
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'am trying to create a generic class that contains a list of generic type
I am trying to create a template class which contains a static list of
I am trying to create a class that implements the IUnknown interface. I have
Well im trying to create a custom container class that contains in my case
I'm trying to create a view that contains a list of checkboxes that is
I am trying to create a String[] which contains only words that comprise of
I have a list that contains FrameworkElements and I want to create an extension
I'm trying to create a class that inherits from ListBox and adding the property
I'm trying to create a class that manages the events of a combo box
I'm trying to create a class that can instantiate arrays at runtime by giving

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.