1
Answer

New to OOP and C#

Chuck Salerno

Chuck Salerno

16y
2.2k
1

If class A constructs a instance of class B and sets a public variable in class B, how can class C call a member of class B?

How does C# manage the contruction of the same class?

 

Chuck

Answers (1)
0
Brandon Lewis
NA 603 116k 16y
Class C would have to have to have access to the instance of class B somehow. Either by having and instance of C as a member of class B, or by exposing the member of B that you want to access. This might be easier if you used "actual" classes, I always like to do shapes... like, Shape, Circle, and Sphere where Shape is a base class, Circle inherits from Shape, and Sphere inherits from Circle.

As for your second question, how the construction chain is executed depends on where you have intialized your variables in code. It might be easier to explain if you code up something and ask questions about it :)