C
cmelnick
I have a custom class that basically consists of two elements, a name
(String) and value (object). I am a bit confused on how to clone or
make a copy of an instance of my object. If I have:
public class MyItem {
private string name;
private object value;
public MyItem() {
}
public string Name { get{...} set{...} }
public object Value { get{...} set{...} }
}
how do I make sure that it is a true copy, with no cross references?
If I added a Clone method something like this:
public MyItem Clone() {
MyItem temp = new MyItem();
temp.Name = this.name;
temp.Value = this.value;
}
wouldn't the name and value refer to the original instances of name and
value? How would I truly copy objects?
(String) and value (object). I am a bit confused on how to clone or
make a copy of an instance of my object. If I have:
public class MyItem {
private string name;
private object value;
public MyItem() {
}
public string Name { get{...} set{...} }
public object Value { get{...} set{...} }
}
how do I make sure that it is a true copy, with no cross references?
If I added a Clone method something like this:
public MyItem Clone() {
MyItem temp = new MyItem();
temp.Name = this.name;
temp.Value = this.value;
}
wouldn't the name and value refer to the original instances of name and
value? How would I truly copy objects?