Normally you can do this and pass the reference type by reference and
the new keyword won't make the variables point to different objects:
static void Main(string[] args)
{
Object origObj = new Object();
ExampleMethod(ref origObj);
}
void ExampleMethod(ref Object newObj)
{
//origObj will also reference the newly created object with the following line. origObj and newObj will point to the same object.
newObj = new Object();
}
I'd like to do this, without using a method to do it:
static void Main(string[] args)
{
Object origObj = new Object();
Object newObj;
// something that would mean the same as the following line:
ref origObj = ref newObj;
// origObj also should reference the new object with the following line. Without the above line which isn't valid, newObj and origObj will point to different objects.
newObj = new Object;
}
Thanks!