0

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's Index?
      End Sub
   End Class
End Class

then I can't use MyBase because it's not derived and I can't pass the instance of the parent to Inner's constructor because Test is shared... I also cannot refer to it as Outer.Index because Outer doesn't yet exist at the time Inner is getting compiled, and of course, in a simple reference the referenced field would be that defined in Inner... so how do I do it?

ekkis
  • 9,804
  • 13
  • 55
  • 105

1 Answers1

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.

competent_tech
  • 44,465
  • 11
  • 90
  • 113
  • if I were to declare Inner.Index as Shared then it becomes a simple issue of shadowing, so my question is basically: how do I overcome the shadow? most languages provide some mechanism to refer to an outer context... – ekkis Jul 25 '12 at 20:56
  • Sorry, re-read your message. I missed the original Shared Index and was focused on the inner index instead. Please see my revised answer. – competent_tech Jul 25 '12 at 22:04