Custom Classes - HowTo access property of parent instance from child instance
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Custom Classes - HowTo access property of parent instance from child instance

Threaded View

  1. #1
    Join Date
    Dec 2007
    Posts
    1

    Question Custom Classes - HowTo access property of parent instance from child instance

    How to access a property of the PARENT custom class instance from a CHILD custom class instance.

    Simply as a convenience for discussion ... let's assume

    A Mammal has teeth
    Teeth are an array of Tooth's
    From inside one instance of the TOOTH class ...
    ... how do I get access to a property (Carnivore) in the MAMMAL class?

    '-------------------------------------------------------------
    Public Class Mammal
    Private myTeeth As New Teeth()
    Public Sub New()
    End Sub
    Private pCarnivore As Boolean = False
    Public Property Carnivore() As Boolean
    Get
    Return pCarnivore
    End Get
    Set(ByVal value As Boolean)
    pCarnivore = value
    End Set
    End Property
    End Class

    '-------------------------------------------------------------
    Public Class Teeth
    Private myTooth() As Tooth
    Public Sub New()
    End Sub
    End Class

    '-------------------------------------------------------------
    Public Class Tooth
    Public Sub New()
    End Sub
    Private pLngth As Integer
    Public Property Lngth() As Integer
    Get
    Return pLngth
    End Get
    Set(ByVal value As Integer)
    pLngth = value
    End Set
    End Property

    ===================
    so right here ...
    inside this instance of Tooth class ...
    ... how can I discover if the parent Mammal is a Carnivore?
    ===================

    End Class
    '-------------------------------------------------------------
    Last edited by volking; February 23rd, 2009 at 11:22 AM. Reason: Text lost indentation - tried to put it back - arrrrrgh!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center