Hello,
I was looking at code that implemented the ICloneable interface for one of the classes.
The class was as follows:
public class TempClass
{
String[] names;
String[] values;
}
A partial class was created that implemented TempClass
public partial class TempClass:ICloneable
{
public Object Clone()
{
TempClass cloneClass = new TempClass();
String[] cloneNames = new String[this.names.Length - 1];
String[] cloneValues = new String[this.values.Length -1];
Array.Copy(this.names,cloneNames,this.names.Length);
Array.Copy(this.values,cloneValues,this.values.Length);
cloneClass.names = cloneNames;
cloneValues.values = cloneValues;
return cloneClass;
}
}
I was wondering if this would be a valid way of doing a deep copy of an object? What raises flags here is the intermediate structures cloneNames and cloneValues that are used to copy the values of the original object and have the member variables Names and Values point to it and then return the object reference that was created in the clone method.
Any feedback on this snippet will be well appreciated
Thanks