0

假设我们有:

Class Outer
   Public Shared Index As Integer
   Class Inner
      Private Index As Integer
      Public Shared Sub Test()
         ' how do I refer to the parent's Index?
      End Sub
   End Class
End Class

然后我不能使用MyBase,因为它不是派生的,并且我不能将父级的实例传递给 Inner 的构造函数,因为 Test 是共享的......我也不能引用它,Outer.Index因为 Outer 在 Inner 时还不存在被编译,当然,在一个简单的引用中,引用的字段将是在 Inner 中定义的......那我该怎么做呢?

4

1 回答 1

0

After re-reading your question, I have removed my previous answer.

I just tested the following class in VS2010:

Class Outer
    Public Shared Index As Integer
    Class Inner
        Private Index As Integer
        Public Shared Sub Test()
            Debug.WriteLine(Outer.Index)
        End Sub
    End Class
End Class

I then added the following code to test:

    Outer.Index = 1
    Outer.Inner.Test()

When I execute this code, "1" is printed in the Immediate window.

于 2012-07-25T19:12:02.970 回答