M
marco_segurini
Hi,
the 'user' class describes what is my target:
I want to save a reference to a class instance and a reference to the
reference to the class instance calling a 'user' member function and
later
use them in another member function to restore the original value.
Is there any C# programming technique that may help me?
Thanks for any help.
Marco.
class MyClass
{
int i_;
public MyClass(int val) { i_ = val; }
public void Dump() { System.Console.WriteLine(i_); }
};
class user
{
//ref MyClass refMyClass_ = null; <--- temp ref-ref
MyClass iOrg_ = null;
public user(ref MyClass i)
{
//refMyClass_ = ref i; // <--- here I want to save the ref-ref
iOrg_ = i;
i = new MyClass(5);
}
~user()
{
//refMyClass_ = iOrg_; //<--- here I want to use ref and ref-ref to
restore the original value
}
};
class Program
{
static void Main(string[] args)
{
MyClass i = new MyClass(1);
i.Dump();
{
user u = new user(ref i);
i.Dump();
}
i.Dump();
}
}
/////
Output I get
1
5
5
Output I wish:
1
5
1
the 'user' class describes what is my target:
I want to save a reference to a class instance and a reference to the
reference to the class instance calling a 'user' member function and
later
use them in another member function to restore the original value.
Is there any C# programming technique that may help me?
Thanks for any help.
Marco.
class MyClass
{
int i_;
public MyClass(int val) { i_ = val; }
public void Dump() { System.Console.WriteLine(i_); }
};
class user
{
//ref MyClass refMyClass_ = null; <--- temp ref-ref
MyClass iOrg_ = null;
public user(ref MyClass i)
{
//refMyClass_ = ref i; // <--- here I want to save the ref-ref
iOrg_ = i;
i = new MyClass(5);
}
~user()
{
//refMyClass_ = iOrg_; //<--- here I want to use ref and ref-ref to
restore the original value
}
};
class Program
{
static void Main(string[] args)
{
MyClass i = new MyClass(1);
i.Dump();
{
user u = new user(ref i);
i.Dump();
}
i.Dump();
}
}
/////
Output I get
1
5
5
Output I wish:
1
5
1