Creating a tree with generics

P

Polaris431

I need to implement a tree structure that can accept various types of
classes or structs. When the tree is created, all of its nodes are
based on a single type and not a mixture of types.

Generics seem to be the solution. However when I look at the
System.Collections.Generic namespace, there isn't anything specific
for building generic trees. There are however classes in this
namespace that I can use to build a tree. My question is, is this the
way I should go about creating the tree? Or do any of the existing
classes in this namespace have built-in tree functionality?

My tree is not for GUI purposes, so I don't want to use the TreeView
class which appears to have limitations that are overcome by Generics.

Thanks
 
N

Nicholas Paldino [.NET/C# MVP]

Polaris431,

There isn't any data structure out of the box in the framework which
will help you. However, you can use generics yourself to create tree
structure which takes a parameterized type for the value of your nodes.

As Neils said as well, there are third party implementations which might
be suitable for you as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top