.Net 集合:节点叶

发布于 2024-09-10 16:30:17 字数 545 浏览 1 评论 0原文

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

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

Is there a built in node-like collection that will allow me to store information within information without building long hard to read generic declarations?

C# or VB.Net solutions would be appreciated.

For example:

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)

Logical Representation:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断舍离 2024-09-17 16:30:17

没有内置任何东西。看看这个

Nothing built in. Take a look at this.

清风挽心 2024-09-17 16:30:17

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

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
}

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

There is nothing builtin, you're probably better off building your own class for each tree node.

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
}

And only one private generic class!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文