Reputation: 19356
Well, I have to classes, ClassA is the main class and the ClassB is the auxiliar class. the code is this.
class ClassA
{
private void myMthod()
{
MyClassB myClassB = new ClasB();
CustomObject myCustomObject = new CustomObject();
myClassB.MyMethodOnClassB(myCustomObject);
if(miCustomObject == null)
{
//code in case of null
}
else
{
//code in case of not null
}
}
}
class ClassB
{
CustomObject _myCustomObjectOnB;
public ClassB(CustomObject paramCustomObject)
{
_myCustomObjectOnB = paramCustomObject;
}
public MyMethodOnClassB()
{
_myCustomObject = null;
}
}
Well, the idea is that when I set to null the variable _myCustomObject on ClassB, in the ClassA myCustomObject would be null. But I know that in this case the code does not work because in the ClassB I am modify a reference different to the reference of the variable on the classA.
The idea is to modify the same reference, because I would like to create a dialog in an application that use the MVVM pattern and I would like to use CustomObject as communication variable, as result of the dialog.
Thank so much.
Upvotes: 0
Views: 87
Reputation: 2817
Try this:
class ClassA
{
private void myMthod()
{
MyClassB myClassB = new ClasB();
CustomObject myCustomObject = new CustomObject();
myClassB.MyMethodOnClassB(ref myCustomObject);
if(miCustomObject == null)
{
//code in case of null
}
else
{
//code in case of not null
}
}
}
class ClassB
{
CustomObject _myCustomObjectOnB;
public ClassB(CustomObject paramCustomObject)
{
_myCustomObjectOnB = paramCustomObject;
}
public MyMethodOnClassB(ref CustomObject customObject)
{
_myCustomObject = customObject = null;
}
}
Upvotes: 2