Access shared parent fields / properties in nested classes

suppose we have:

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

then I cannot use MyBaseit because it was not received, and I cannot pass the parent instance to the Inner constructor because Test is generic ... I also can not refer to it as Outer.Indexbecause Outer doesn’t exist yet in the time when Inner is compiled and, of course, in a simple link, the link field will be defined in the internal ... so how to do this?

0
source share
1 answer

After reading your question again, I deleted 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

Then I added the following code for testing:

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

, "1" "".

0

All Articles