【发布时间】:2015-08-04 07:26:02
【问题描述】:
我正在编写一个程序,其中我在另一个类中有一个类。我需要知道我是否可以从内部访问外部类的属性。
类似这样的:
Module mod1
Public Class c1
Public var1 As Integer = 3
Public Class c2
Public Sub doSomething()
'I need to access var1 from here. Is it possible?
End Sub
End Class
End Class
End Module
非常感谢您的帮助!
编辑:我想做的例子
Dim obj1 As New c1 'Let's suppose that the object is properly initialized
Dim obj2 As New obj1.c2 'Let's suppose that the object is properly initialized
obj2.doSomething() 'Here, I want to affect ONLY the var1 of obj1. Would that be possible?
【问题讨论】:
-
您需要
c1的实例才能访问var1,或者您需要将其设为共享变量。 -
@Saragis 我不能让它共享,因为 c1 的每个实例都会有不同的值,我不能实例 c1 因为我不想要一个新对象,但是那个c2 对象在里面。如果我没有正确解释自己,我在原帖中添加了一个示例