在过去的一个小时里,我一直在努力做到这一点,但我仍然可以让它发挥作用。
我正在尝试创建一个多深度数组。让我解释一下我的丈夫。
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他们必须有一个标签,这里应该是老板,经理或员工的名字。
有办法这样做吗?
谢谢
发布于 2014-04-25 15:04:26
下面是我如何做到这一点的:
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")
...带有结果格式

这将如何帮助一些人
发布于 2014-04-24 14:27:27
最好只是有一个类来表示一个人的层次结构,并在其下面列出一个人的列表。就个人而言,多深度数组可能有点复杂,特别是对于要维护代码的人而言。
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 Classhttps://stackoverflow.com/questions/23269158
复制相似问题