【问题标题】:.Net Collections: Node-Leaf.Net 集合:节点叶
【发布时间】:2010-07-22 19:40:46
【问题描述】:

是否有内置的类似节点的集合,可以让我在信息中存储信息,而无需构建长而难以阅读的通用声明?

C# 或 VB.Net 解决方案将不胜感激。

例如:

dim base as new Dictionary(of String, Dictionary(of String, List(of String)))
dim mid as new Dictionary(of String, List(of String)
dim leaf as new List(of String)
leaf.add("leaf1")
leaf.add("leaf2")
mid.add("middle", leaf)
base.add("base", mid)

逻辑表示:

               / leaf
        mid    - leaf
     /         \ leaf
base
     \         / leaf
        mid    - leaf
               \ leaf

【问题讨论】:

    标签: .net generics collections


    【解决方案1】:

    没有内置任何东西。看看this

    【讨论】:

      【解决方案2】:

      没有内置任何东西,您最好为每个树节点构建自己的类。

      public class Node {
        private List<Node> children = new List<Node>();
      
        public void Node(Node parent,Object node_data) {
          ...
        }
      
        // put some methods for adding, removing, retrieving children here
      }
      

      而且只有一个私有泛型类!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-08-08
        • 2012-06-19
        • 1970-01-01
        • 2022-11-16
        • 2020-06-10
        • 1970-01-01
        • 2016-10-08
        • 1970-01-01
        相关资源
        最近更新 更多