Creating a tree with generics

  • Thread starter Thread starter Polaris431
  • Start date Start date
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
 
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.
 
Back
Top