mmexchange
asked on
C# Class Method passing reference
If I have a (C# VS2008) class (object) with fields and methods (A), and those method instanciate another object (B) which has fields and methods ... how do I reference the (A) fields/methods from within a (B) method? And what if a method in the (B) object instanciates another object (C) and wants to reference the (A) object fields/methods ... what is the proper syntax? For example:
class MyClassA
int ItemAint;
MyClassB CB = new MyClassB;
public string MyMethodA1()
{ CB.DoItemB(???); }
public string MyMethodA2()
{ // some stuff }
class MyClassB
int itemBint;
private string MyMethodB(???)
{ if ( ???.itemAint == 1 )
{ ???.MyMethodA2(); } }
I'm thinking this might work: (is it correct?)
class MyClassA
int ItemAint;
MyClassB CB = new MyClassB;
public string MyMethodA1()
{ CB.DoItemB(this); }
public string MyMethodA2()
{ // some stuff }
class MyClassB
int itemBint;
private string MyMethodB(MyClassA obj)
{ if ( obj.itemAint == 1 )
{ obj.MyMethodA2(); } }
class MyClassA
int ItemAint;
MyClassB CB = new MyClassB;
public string MyMethodA1()
{ CB.DoItemB(???); }
public string MyMethodA2()
{ // some stuff }
class MyClassB
int itemBint;
private string MyMethodB(???)
{ if ( ???.itemAint == 1 )
{ ???.MyMethodA2(); } }
I'm thinking this might work: (is it correct?)
class MyClassA
int ItemAint;
MyClassB CB = new MyClassB;
public string MyMethodA1()
{ CB.DoItemB(this); }
public string MyMethodA2()
{ // some stuff }
class MyClassB
int itemBint;
private string MyMethodB(MyClassA obj)
{ if ( obj.itemAint == 1 )
{ obj.MyMethodA2(); } }
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.