468,134 Members | 1,188 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,134 developers. It's quick & easy.

Reference parent object of child object?

Is there a way to reference the "parent" object that creates a child object
from within the child object? Or do I have to pass a reference to the parent
object to the constructor of the child object so that the child object
"knows" who is creating it?

ie: how would I do something like this:

Object1 parent = new Object1();
parent.CreateObject2() // object1 creates a new object called object2
object2.parent // I want to be able to refer back to the
parent from the newly created "child object"

or when I create object2 do I have to pass a reference to "parent" in order
to reference it from within object2.

Thanks,

Alex

Jul 21 '05 #1
1 1726
"Alex" <Al**@discussions.microsoft.com> wrote in message
news:A3**********************************@microsof t.com...
Is there a way to reference the "parent" object that creates a child
object
from within the child object? Or do I have to pass a reference to the
parent
object to the constructor of the child object so that the child object
"knows" who is creating it?


Yes. That's how you have to do it.
John Saunders
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by marcadonis | last post: by
10 posts views Thread by Goran Djuranovic | last post: by
7 posts views Thread by vunet | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.