If you want object B to be able to talk to A. That is easy. It is a member
of B; just use its name.
If you want object A to know it's "parent", you can set this relationship up
yourself. As an example, you might define the class A as
public class ObjectA {
public ObjectA(ObjectB parent) {
_parent = parent;
}
private ObjectB _parent;
}
Now, to create an A you will have to say,
ObjectB myB = new ObjectB();
ObjectA myA = new ObjectA(myB);
Alternatley, depending on the relationship you are trying to establish, you
might create method of B like:
public ObjectA CreateSubObject A() {
return new ObjectB(this);
}
Then, you could use the code:
ObjectB myB = new ObjectB();
ObjectA myA = myB.CreateSubOb jectA();
But, from a design persepctive here, please take care. Each class should not
know about the internals of the other class, and each class should have a
single responsibility. An example of this pattern is exemplified by controls
on a form. You can create a control and add it to the form with code similar
to:
Label label = new Label();
label.Name = "myLabel";
label.Text = "This is my label";
form1.Controls. Add(label);
Hope this helps...
Frisky
"M Shafaat" <MS******@discu ssions.microsof t.com> wrote in message
news:7F******** *************** ***********@mic rosoft.com...
Hi!
Consider the following:
Object A is a member of Object B.
Object A has a known identifier.
Object B has an unknown identifier.
How do we reference Object B using Object A?
I have tried using "owner", "container" , "parent", etc. without success.
Please help.
It must be possible, there has to be a tie between these two objects, e.g.
you can reference Object A using Object B by qualifying, i.e.
ObjectB.OBjectA .
Regards
M Shafaat