Access Parent Class without declaring property

31 Views Asked by At

I know this is a very silly thing to ask, but is this possible?

Says I have this class

Class A
{
    string propertyA;
    Public A()
    {
        // do something here             
    }
}

Then this :

Class B
{
    A classA;
    string propertyB;
}

Normally I would do this :

B classB = new B();
A classA = new A(); 
B.classA = classA; 

Is there anyway to achieve something like this :

Class A
{
    string propertyA;
    Public A()
    {
        // get or set B's properties 
        // but the problem is this class doesnt have a Parent property 
    }
}
1

There are 1 best solutions below

7
On BEST ANSWER

No, there is no way to achieve that.

To access another object, you need a reference to it.

If you don't have a reference stored locally, you need a way to find or obtain that reference.

If you have neither, you can't access it.