我在MyClass2中有以下属性:
Private MyClass1Array(1 To 4) As MyClass1
其中MyClass1是我定义的另一个类。我不知道如何处理这个属性:它不能公开,所以我在MyClass2模块中写了这个:
Public Property Let SetMyClass1Array(i As Integer, c As MyClass1)
MyClass1Array(i) = c
End Property
Public Property Get GetMyClass1Array(i As Integer) As MyClass1
GetMyClass1Array = MyClass1Array(i)
End Property
但这也行不通。如何正确编写此属性?谢谢!
答案 0 :(得分:3)
使用类对象时,需要在处理对象引用时使用Set
,而不是原始数据类型值。
Public Property Let SetMyClass1Array(i As Integer, c As MyClass1)
Set MyClass1Array(i) = c
End Property
Public Property Get GetMyClass1Array(i As Integer) As MyClass1
Set GetMyClass1Array = MyClass1Array(i)
End Property