473,241 Members | 1,481 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,241 software developers and data experts.

Collection Advice Requested

Using .NET 3.5... I have the following class:

class NodeDescriptor
{
// Properties only in this class
public int NodeID { get; private set; }
public int ParentNodeID { get; private set; }
public string SomeStringValue { get; set; }
// etc... (2 more int and 7 more string properties, that's all.)
}
I need to create a collection of these NodeDescriptor objects. My question
is about how to best implement this collection. This collection needs to
expose a method (named something like GetChildNodes()) that returns all of
the immediate child nodes of a given node. So, for example, if the
collection contains 5 NodeDescriptor instances with the following property
values...

NodeID -- ParentNodeID -- SomeStringValue
23 -- null -- "some string"
37 -- 23 -- "another string"
19 -- 23 -- "yet another"
94 -- 37 -- "okey dokey"
51 -- 23 -- "yes, of course"

.... the GetChildNodes() method would return the NodeDescriptor instances
with NodeID = 37, 19, and 51 when passed NodeID = 23 (because the
parentNodeID = 23 for each of these NodeDescriptor objects).

How can I best implement this collection - given the objectives of NOT
looping through each contained NodeDescriptor instance? List<NodeDescriptor>
would not work for me because I'd have to loop through it, as far as I know,
and I don't want to loop. Can LINQ be used here - or would that be overkill?
If possible I'd like the GetChildNodes() method to return a collection of
NodeDescriptor objects.

A couple of relevant considerations:
1. Only imediate child nodes, and *not* grand child nodes, are to be
returned. So the NodeDescriptor instance with NodeID = 94 would not be
returned when the GetChildNodes() method is passed NodeID = 23 (because it's
ParentNodeID is 37).

2. This collection will typically contain 5-8 (rarely more than 12, and
never more than 30) NodeDescriptor instances.

3. The NodeDescriptor instances should be able to be inserted into this
collection collection in any arbitrary sequence (i.e., no particular
sequence is assumed).

Thanks!

Jun 27 '08 #1
2 1108
On May 21, 4:30 pm, "Jordan S." <A...@B.comwrote:
Using .NET 3.5... I have the following class:

class NodeDescriptor
{
// Properties only in this class
public int NodeID { get; private set; }
public int ParentNodeID { get; private set; }
public string SomeStringValue { get; set; }
// etc... (2 more int and 7 more string properties, that's all.)

}

I need to create a collection of these NodeDescriptor objects. My question
is about how to best implement this collection. This collection needs to
expose a method (named something like GetChildNodes()) that returns all of
the immediate child nodes of a given node. So, for example, if the
collection contains 5 NodeDescriptor instances with the following property
values...

NodeID -- ParentNodeID -- SomeStringValue
23 -- null -- "some string"
37 -- 23 -- "another string"
19 -- 23 -- "yet another"
94 -- 37 -- "okey dokey"
51 -- 23 -- "yes, of course"

... the GetChildNodes() method would return the NodeDescriptor instances
with NodeID = 37, 19, and 51 when passed NodeID = 23 (because the
parentNodeID = 23 for each of these NodeDescriptor objects).

How can I best implement this collection - given the objectives of NOT
looping through each contained NodeDescriptor instance? List<NodeDescriptor>
would not work for me because I'd have to loop through it, as far as I know,
and I don't want to loop. Can LINQ be used here - or would that be overkill?
If possible I'd like the GetChildNodes() method to return a collection of
NodeDescriptor objects.

A couple of relevant considerations:
1. Only imediate child nodes, and *not* grand child nodes, are to be
returned. So the NodeDescriptor instance with NodeID = 94 would not be
returned when the GetChildNodes() method is passed NodeID = 23 (because it's
ParentNodeID is 37).

2. This collection will typically contain 5-8 (rarely more than 12, and
never more than 30) NodeDescriptor instances.

3. The NodeDescriptor instances should be able to be inserted into this
collection collection in any arbitrary sequence (i.e., no particular
sequence is assumed).

Thanks!
Heres one implementation.. not saying its the best.

Its the same thing you have but with few changes.

public int NodeID { get; private set; }
public NodeDescriptor ParentNode { get; private set; }
private List<NodeDescriptorchildren ;
everytime you add a child node you will have to add a referce to the
current node as parent.

I think that should do what you are trying to do
Jun 27 '08 #2
On May 21, 9:30 pm, "Jordan S." <A...@B.comwrote:

<snip>
I need to create a collection of these NodeDescriptor objects. My question
is about how to best implement this collection. This collection needs to
expose a method (named something like GetChildNodes()) that returns all of
the immediate child nodes of a given node.
Sounds like you want an IDictionary<int,IEnumerable<NodeDescriptor>-
or in more concrete terms, something like

Dictionary<int,List<NodeDescriptor>>

See http://msmvps.com/blogs/jon.skeet/ar...tiful-one.aspx
for some code which may help.

Jon
Jun 27 '08 #3

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

Similar topics

0
by: Simon Thompson | last post by:
Hi, I have a VB6 ActiveX DLL that we use for printing. It iterates through the printers collection to set the printer to the one the user requested. This is called from ASP (VB Script) pages,...
2
by: CJM | last post by:
I'm running a stored procedure that inserts a record into a table then returns the Identity field value. I've done this kind of thing plenty of times in the past, but I'm obviously doing something...
9
by: obhayes | last post by:
Hi, I have two tables Table A and B, below with some dummy data... Table A (contains specific unique settings that can be requested) Id, SettingName 1, weight 2, length Table B (contains...
1
by: Chris Dunaway | last post by:
VB.Net: I have create a custom collection to hold instances of my custom class. The collection has an Item property which is set as the default property. I can use code such as this to...
1
by: Dan H. | last post by:
Hello, I have an application that requires a collection that is sorted by a double field first, and then by a long field. So, lets say I have an class that has 2 fields called time, priority. I...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
5
by: Miljana | last post by:
Hi, I have one problem with cookies in ASP.NET application. It seems that I can not retreive cookie from Request.Cookies collection. I put cookie in Response.Cookies collection, and after page...
2
by: indhu | last post by:
Hi its not working, i want only distinct record. here its repeated records coming. accdb = "SELECT DISTINCT sequence FROM scene WHERE sceneid = '" & myquery & "' " and when i select the...
2
by: Sticksboy | last post by:
I keep getting this error message - Item cant be found in the collection corresponding to the requested name or ordinal I dont understand what it means to be honest. I am trying to get the code...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.