I keep repeating the same problem when the object I want to reference is copied or where the object I want to copy is referenced. This happens when I use the = operator.
For example, if I submit an object to another form, that is:
SomeForm myForm = new SomeForm(); SomeObject myObject = new SomeObject(); myForm.formObject = myObject;
... and then change the object in the form, the original object will not be changed. It is as if the object was copied and not referenced. However, when I do this:
SomeObject myObject = new SomeObject(); SomeObject anotherObject = new SomeObject(); anotherObject = myObject;
... and then change anotherObject , myObject will also change.
The most aggravating case is when I try to clone one of my specific objects:
public class SomeObject { double value1, value2;
when i do this ...
SomeObject obj1 = new SomeObject(1, 2); SomeObject obj2 = new SomeObject(); obj2.Clone(obj1);
... obj1 referenced, and any changes to obj2 changed by obj1 .
System objects such as int, double, string , etc., seem to always be copied, except in the case of the cloning method described above.
My question is that we do not take into account the use of the ref keyword in functions when the object is copied and when the object receives a link in each case of the question (i.e., when switching to functions during configuration, like the other objects (for example, the first two above example) when copying member variables such as third example etc.)?
reference c # copy
Mike Webb Dec 03 '10 at 16:58 2010-12-03 16:58
source share