How to get the parents object?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi guys,
I have three classes like followling:

Class A
{
...
}

Class B
{
...
public A a1 = new A();
}

Class C
{
...
public A a1 = null;
}

class Test
{
void Main()
{
B b1 = new B();
C c1 = new C();
c1.a1 = b1.a1;

this.GetParents(b1.a1);
}

private void GetParents(A a)
{
// ??? how to get b1 and c1 from a?
}
}

My question is: how can I get the instance of b1 and c1 from a1. I mean is
there have any C# basic function to get the instances which hold a1?
 
Hi guys,
I have three classes like followling:

Class A
{
...

}

Class B
{
...
public A a1 = new A();

}

Class C
{
...
public A a1 = null;

}

class Test
{
void Main()
{
B b1 = new B();
C c1 = new C();
c1.a1 = b1.a1;

this.GetParents(b1.a1);
}

private void GetParents(A a)
{
// ??? how to get b1 and c1 from a?
}

}

My question is: how can I get the instance of b1 and c1 from a1. I mean is
there have any C# basic function to get the instances which hold a1?

No. You would have to have a Parents field / property in A and add the
parent object to it when you parent an A instance inside some other
object.

Either that, or trip through all of the objects that might contain a
particular instance of A and look for it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top