I have:
instance1 = instance2;
how do I disconnect them from one another, so that altering one will not affect the other?
EDIT: I want them referencing the same object (so I can’t clone), and later – not. But I still want both instances of the class – so I can’t ‘null’ them.
Thanks
EDIT:
myclass a = new myclass();
a.integer = 1;
myclass b = new myclass();
b.integer = 2;
a = b;
//All changes to one will affect the other, Which is what I want.
//<More lines of the program>
//Now I want 'a' to point to something else than 'b'. and I’m missing the code
//so that the next line will not affect 'b'.
a.integer = 1;
Text = b.integer.ToString();
//I need b.integer to still be = 2, it’s not.
With:
class myclass
{
public int integer;
}
EDIT:
This is the answer:
@ispiro but when you say a.integer = 1 you aren't changing the pointer, you are following the pointer and changing the value at the end of it. – Davy8
I had thought that changing both ‘a’ and ‘a.integer’ would be the same in the sense that changing them would either change pointer-‘a’ or won’t. But in fact: the first does, the second doesn’t.
Thanks everyone.
So in the example above, if I add:
a = c;// where c is another instance of 'myclass'.
It will change ‘a’ to point somewhere else than ‘b’.
But:
a.integer = 1;
did not.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…