首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >.NET中的多深度阵

.NET中的多深度阵
EN

Stack Overflow用户
提问于 2014-04-24 12:39:45
回答 2查看 72关注 0票数 1

在过去的一个小时里,我一直在努力做到这一点,但我仍然可以让它发挥作用。

我正在尝试创建一个多深度数组。让我解释一下我的丈夫。

代码语言:javascript
复制
Boss
    Manager
        Employee
        Employee
        Employee
    Manager
        Employee
        Employee
        Employee
Boss
    Manager
        Employee
        Employee
        Employee
    Manager
        Employee
        Employee
        Employee
Boss
    Manager
        Employee
        Employee
        Employee
    Manager
        Employee
        Employee
        Employee

他们必须有一个标签,这里应该是老板,经理或员工的名字。

有办法这样做吗?

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-25 15:04:26

下面是我如何做到这一点的:

代码语言:javascript
复制
Public Class sousdir
    Public name As String
    Public services As New List(Of String)
End Class

Public Class direction
    Public name As String
    Public sousdirs As New List(Of sousdir)
End Class

Dim directions As New List(Of direction)

directions.Add(New direction)
directions(0).name = "Direction 1"
directions(0).sousdirs.Add(New sousdir)
directions(0).sousdirs(0).name = "Sous Direction 1"
directions(0).sousdirs(0).services.Add("Service 1")
directions(0).sousdirs(0).services.Add("Service 2")
directions(0).sousdirs(0).services.Add("Service 3")
directions(0).sousdirs.Add(New sousdir)
directions(0).sousdirs(1).name = "Sous Direction 2"
directions(0).sousdirs(1).services.Add("Service 1")
directions(0).sousdirs(1).services.Add("Service 2")
...

带有结果格式

这将如何帮助一些人

票数 0
EN

Stack Overflow用户

发布于 2014-04-24 14:27:27

最好只是有一个类来表示一个人的层次结构,并在其下面列出一个人的列表。就个人而言,多深度数组可能有点复杂,特别是对于要维护代码的人而言。

代码语言:javascript
复制
Sub Main()

    Dim bosses As New List(Of Hierarchy)

    bosses.Add(New Hierarchy)
    bosses(0).Person = New Person
    bosses(0).Person.Name = "Boss"

    bosses(0).Childs.Add(New Hierarchy)
    bosses(0).Childs(0).Person = New Person
    bosses(0).Childs(0).Person.Name = "Manager"

    bosses(0).Childs(0).Childs.Add(New Hierarchy)
    bosses(0).Childs(0).Childs(0).Person = New Person
    bosses(0).Childs(0).Childs(0).Person.Name = "Employee"

    bosses(0).Childs(0).Childs.Add(New Hierarchy)
    bosses(0).Childs(0).Childs(1).Person = New Person
    bosses(0).Childs(0).Childs(1).Person.Name = "Employee"

    For Each boss In bosses
        Console.WriteLine(boss.Person.Name)

        For Each manager In boss.Childs
            Console.WriteLine("   " & manager.Person.Name)

            For Each employee In manager.Childs
                Console.WriteLine("      " & employee.Person.Name)
            Next
        Next
    Next

End Sub

Class Hierarchy
    Public Person As Person
    Public Childs As New List(Of Hierarchy)
End Class

Class Person
    Public Name As String
End Class
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23269158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档