Deep replication is a copy of the reference type.
Replication is a replication of value type.
For example:
Using system;
Using system. Collections. Generic;
Using system. text;
Namespace Test
{
Public class content
{
Public int val;
}
// Icloneable is inherited only when deep replication is used.
// Public class cloner: icloneable
Public class cloner
{
Public content mycontent = new content ();
Public cloner (INT newval)
{
Mycontent. Val = newval;
}
// Copy in a shortest Mode
// Use system. Object. memberwiseclone () for shortest replication. Use the getcopy method.
Public object getcopy ()
{
Return memberwiseclone ();
}
// Deep copy:
Public object clone ()
{
Cloner clonedcloner = new cloner (mycontent. Val );// An object is instantiated.
Return clonedcloner;
}
}
}
// Main Function
Using system;
Using system. Collections. Generic;
Using system. text;
Namespace Test
{
Class Program
{
Static void main (string [] ARGs)
{
Cloner mysource = new cloner (5 );
Cloner mytarget = (cloner) mysource. getcopy ();// The depth is cloner.
Console. writeline ("mytarget. mycontent. Val = {}", mytarget. mycontent. Val );
Mysource. mycontent. Val = 2;
Console. writeline ("mytarget. mycontent. Val = {}", mytarget. mycontent. Val );
}
}
}