473,394 Members | 1,701 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,394 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 1115
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...
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
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.