Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hi folks

Thank you for the feedback. The solutions assume that I know number of objects in advance.

A simple analogy would be to assume a GUI (Window form) with a drop down where you can select a school district from many.

Once you select a school district (the A object), you drill down to number of schools in this district which can vary (B objects). For each B object there are classrooms objects (C objects). Each C object has array of Female students, array of male students, a single door, a single blackboard ... and so forth. These are the attributs of the C objects.

Thanks
Mike
Posted
Updated 11-Apr-11 16:49pm
v2
Comments
Kim Togo 11-Apr-11 10:22am    
Can you give some code example on how far you are now ?
BobJanova 11-Apr-11 10:42am    
Please explain 'key data' a bit more. What is C?

Wayne's answer looks good from the information we have now. A and B certainly will contain a List of B and C respectively.

Ed: Depending on how you're planning on referencing B and C instances, you may want a Dictionary<keyType, B/C> instead

Not sure what's confusing here. For things like this just adopt the simplest possible approach (which will nearly always be the best one):

C#
namespace ABC
{
    class Program
    {
        static void Main()
        {
            C c1 = new C();
            C c2 = new C();
            C c3 = new C();
//...
            B b1 = new B();
            b1.Add(c1);
            b1.Add(c2);
//...
            B b2 = new B();
            b2.Add(c3);
//...
            A a = new A();
            a.Add(b1);
            a.Add(b2);
        }
    }
//...

    class C
    {
        public DateTime CreateDate { get; set; }
//...
        public int Id { get; set; }
    }
//...

    class B : Collection<C>
    {
    }
//...

    class A : Collection<B>
    {
    }
}
 
Share this answer
 
v2
Are you looking at something like this

C#
class a
   {
       public List<b> bObjects { get; set; }
   }
   class b
   {
       public List<c> cObjects { get; set; }
   }
   class c
   {
       //members here
   }


Each object of class a will have a List of class b objects, which would in turn have a list o class c objects.
 
Share this answer
 
I'd do something like this (caution - untested code):

C#
public class a : List<b>
{
    // Adds or inserts a c item and if specified creates a b item for the c item 
    // if the index is out of range
    public bool AddInsertObject(int index, c cItem, bool createB)
    {
        bool success = false;
        if (index >= 0 && (index < this.Count)
        {
            this[index].Add(cItem);
            success = true;
        }
        else
        {
            if (createB)
            {
                b bList = new b();
                bList.Add(cItem);
                this.Add(bList);
            }            
        }
        return success;
    }
}

public class b : List<c>
{
}

public class c
{
    // properties and methods for this object
}

Useage:

C#
a.AddInsertObject(int index, new c(){init properties});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900