How to create a complete, isolated copy of a variable to prevent the copy from changing when changed parent variable.
I have tried some variants: 1. The most easiest variant
var parent = new Class();var clonedParent = parent;// do some changes with parentif (parent == clonedParent) <-- True
var parent = new Class();var clonedParent = parent;// do some changes with parentif (parent == clonedParent) <-- True
2. Variant with
ICloneable
ICloneable
*logic still not changed
class Person : ICloneable{ public string Name { get; set; } public int Age { get; set; } public object Clone() { return new Person { Name = this.Name, Age = this.Age }; }}
class Person : ICloneable{ public string Name { get; set; } public int Age { get; set; } public object Clone() { return new Person { Name = this.Name, Age = this.Age }; }}
if (parent == clonedParent) <-- True
if (parent == clonedParent) <-- True
Still True
3. A little bit harder variant with
ICloneable
ICloneable
class myClass : ICloneable{ public string Name { get; set; } public int Age { get; set; } public object Clone() { return this.MemberwiseClone(); }}
class myClass : ICloneable{ public string Name { get; set; } public int Age { get; set; } public object Clone() { return this.MemberwiseClone(); }}
if (parent == clonedParent) <-- True
if (parent == clonedParent) <-- True
Still True
Do you know any other variants to clone and isolate variable?