473,383 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Collections of Collections in C#

Hi

I have a class that contains an array of another class:

public abstract class Node {}

public class elem1 : Node {
public ArrayList NodeItems1=new ArrayList ();
}

public class elem2 : Node {
public ArrayList NodeItems2=new ArrayList ();

}

So i could have such a tree:
Node
+elem1
++elem2
+elem1
++elem1
+elem2
+elem2
++elem1

How could i iterate over this collections of collections ?

Thanks
Jo
Nov 16 '05 #1
1 1134
Hi,

Why you create two classes with the same structure?

You should be fine with elem1 only, now if you wanna to create a tree
structure you should have to implement it from the Node class, as a node can
be a node or a leaf.
You should also think of using a Strong typed collection instead of
ArrayList, safer and easier to use

maybe something like this:
class Node
{
public ArrayList Childrens=new ArrayList (); //

//Know if I have children
public bool HasChildren{ get{ return Childrens.Count>0;}
}

with the above structure you can create the structure you want.
How to iterate on it depends of how you wanna do it. if you need to return
the nodes ( using an iterator ) or just do some internal process

void ProcessNodes( Node startnode )
{
DoSomething( startnode )

if ( startnode.HasChildren()
foreach( Node currentnode in startnode.Childrens )
ProcessNode( currentnode )

}

The above method do a Deep search first , just as an example.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"jonathan" <jw******@csi.com> wrote in message
news:a8**************************@posting.google.c om...
Hi

I have a class that contains an array of another class:

public abstract class Node {}

public class elem1 : Node {
public ArrayList NodeItems1=new ArrayList ();
}

public class elem2 : Node {
public ArrayList NodeItems2=new ArrayList ();

}

So i could have such a tree:
Node
+elem1
++elem2
+elem1
++elem1
+elem2
+elem2
++elem1

How could i iterate over this collections of collections ?

Thanks
Jo

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: njp | last post by:
BlankHi, How do I create a tightly coupled Object 1 such that when I update it in one collection, it is simultaneously and automatically updated in other collections? The collections are defined...
1
by: Tim T. | last post by:
I'm currently working on a report to forecast production for finished goods. The user can select one or more items to forecast. In addition, they may select one or more warehouses to view...
5
by: Simon | last post by:
Hi all, I am writing a windows application using vb.net on the 1.1 framework. We have in the application, some strongly typed collections that have been written as classes that do not inherit...
4
by: nhmark64 | last post by:
Hi, Does System.Collections.Generic.Queue not have a Synchronized method because it is already in effect synchronized, or is the Synchronized functionality missing from...
4
by: Adam Clauss | last post by:
I ran into a problem a while back when attempting to convert existing .NET 1.1 based code to .NET 2.0 using Generic collections rather than Hashtable, ArrayList, etc. I ran into an issue because...
5
by: WebSnozz | last post by:
Some collections are such that efficient search algorithms work on them such as binary search if the collection is a type which is sorted. I'm wondering how LINQ searches these collections and if...
2
by: Fred Heida | last post by:
Hi, i'm trying to (using managed C++) implment the IEnumerable<Tinterface on my class.. but have a problem with the 2 GetEnumerator method required.... what i have done is... ...
4
by: Sid Price | last post by:
Hello, I have a class of objects (Device) that are managed by another object (Devices) with a collection class (DeviceCollection) inherited from Collections.Hashtable. Each of the Device objects...
5
by: Michi Henning | last post by:
I can pass a generic collection as ICollection<Tjust fine: static void flatCollection(ICollection<intc) {} // ... List<intl = new List<int>(); flatCollection(l); // Works fine Now I...
3
by: Marco Shaw | last post by:
I've got some C# code to create a custom PowerShell cmdlet with these statements: .... using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; .... ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.