Home All Groups Group Topic Archive Search About

vb.net nested class' parent?

Author
10 May 2006 6:44 PM
Craig Buchanan
is there an implicitly-defined Parent property defined for a class that is
nested in another class?  i'm looking to simplify my coding.

At this point, i've defined the class as so:

Class Item

    Private _SubItem As New SubItem(Me)

    'other properties and methods

    Class SubItem

        Private _Parent As Item

        Public ReadOnly Property Parent As Item
            Get
                Return _Parent
            End Get
        End Property

        Friend Sub New (value as Item)
            _Parent=value
        End Sub

        'other stuff

    End Class

End Class

Thanks,

Craig Buchanan

Author
10 May 2006 6:59 PM
Tom Shelton
Craig Buchanan wrote:
Show quoteHide quote
> is there an implicitly-defined Parent property defined for a class that is
> nested in another class?  i'm looking to simplify my coding.
>
> At this point, i've defined the class as so:
>
> Class Item
>
>     Private _SubItem As New SubItem(Me)
>
>     'other properties and methods
>
>     Class SubItem
>
>         Private _Parent As Item
>
>         Public ReadOnly Property Parent As Item
>             Get
>                 Return _Parent
>             End Get
>         End Property
>
>         Friend Sub New (value as Item)
>             _Parent=value
>         End Sub
>
>         'other stuff
>
>     End Class
>
> End Class
>
> Thanks,
>
> Craig Buchanan

There isn't an implicit reference to the containing object.  You will
need to pass that in yourself in your nested class's constructor.

--
Tom Shelton [MVP]