Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

shallow copy vs deep copy c#

// Shallow Copy
A ob1 = new A();
ob1.a = 10;
A ob2 = new A();
ob2 = ob1;
ob1.a = 5; // <-- If you see value of ob2.a after this line, it will be 5

// Deep Copy
A ob1 = new A();
ob1.a = 10;
A ob2 = new A();
ob2.a = ob1.a;
ob1.a = 5; // <-- If you see value of ob2.a after this line, it will be 10.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #shallow #copy #deep #copy
ADD COMMENT
Topic
Name
2+1 =