Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 访问对象';从其内部的对象中删除参数_.net_Vb.net_Basic - Fatal编程技术网

.net 访问对象';从其内部的对象中删除参数

.net 访问对象';从其内部的对象中删除参数,.net,vb.net,basic,.net,Vb.net,Basic,我正在编写一个程序,其中一个类在另一个类中。我需要知道是否可以从内部类访问外部类的属性 大概是这样的: 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?

我正在编写一个程序,其中一个类在另一个类中。我需要知道是否可以从内部类访问外部类的属性

大概是这样的:

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?

您仍然需要在这两个对象之间的某个位置创建链接。下面是一个你如何做到这一点的例子

Dim obj1 As New c1
Dim obj2 As New c2(obj1)

obj2.doSomething()
剂量测量现在可以影响c1和c2中定义的两个变量。实施:

Public Class c1
    Public var1 As Integer = 3
End Class

Public Class c2
    Private linkedC1 As c1

    Public Sub New(ByVal linkedC1 As c1)
        Me.linkedC1 = linkedC1
    End Sub

    Public Sub doSomething()
        'I need to access var1 from here. Is it possible?
        linkedC1.var1 += 1
    End Sub

End Class

您需要一个
c1
的实例才能访问
var1
,或者您需要将其作为一个共享变量。@Saragis我不能将其共享,因为c1的每个实例都有不同的值,我也不能将其共享,因为我不想要一个新对象,而是c2对象所在的对象。如果我没有正确地解释我自己,我在最初的帖子中添加了一个例子,那就是我要做的。非常感谢你!