OO Reference

A

AMP

Hello,
I have a Class A that creates a clB object of type Class B and a clC
object of Class C.
I have a field in clC, 'Class B localB', that I want to hold a
reference to any object of Class B.
Besides passing a parameter to the Class C constructor, how do I pass
a reference of my clB object to the localB field.
Are there multiple ways, if so could you tell me.
Thanks
 
I

Ignacio Machin ( .NET/ C# MVP )

Hello,
I have a Class A that creates a clB object of type Class B and a clC
object of Class C.
I have a field in clC, 'Class B localB', that I want to hold a
reference to any object of Class B.

You mean to one instance of class B , right?
Besides passing a parameter to the Class C constructor, how do I pass
a reference of my  clB object to the localB field.
Are there multiple ways, if so could you tell me.
Thanks

You can use a property or even a method. But note that if you do so
you are implying that the member might not be initialized and you need
to check for that before using it
 
A

AMP

You mean to one instance of class B , right?


You can use a property or even a method. But note that if you do so
you are implying that the member might not be initialized and you need
to check for that before using it

Examples? Yours or maybe a project (tutorial) online.
Thanks
 

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

Top