0

我正在做一个小项目,并在试图保持 OOP 时遇到了一些麻烦。

我有一个全局变量:

Public Stations As New Microsoft.VisualBasic.Collection()

和 2 个类:Station& Unit

Public Class Station

    Property name As String
    Property stype As String
    Property units As New Collection
End Class

Public Class unit
     Property name As String
     Property lbl As String
     Property ip As String
     Property utype As String
End Class

我想你可以在这里看到层次结构:

Collection Stations -> Object Station -> Collection Units -> Object Unit

有一个代码可以从 XML 文件中获取数据,并据此将对象添加到上面的集合中。

但是,我不知道如何根据集合检索单位Stations集合。我试过这样的事情:

    Dim st = Stations.Item("The key of a specific object in the Stations collection")
    Dim stUnits = st.GetType().GetProperty("units")

但是当我试图检索stUnits集合时:

For Each unit In stUnits

它说这stUnits不是一个集合。我有点困惑,感谢您的任何帮助。

4

1 回答 1

0

傻我。忘记设置st为站对象。

Dim st As Station = Stations.Item("The key of a specific object in the Stations collection")

然后,简单地说:

Dim stUnits = st.units
于 2012-05-26T11:27:48.663 回答