Answers for "shallow copy vs deep copy c#"

C#
1

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.
Posted by: Guest on August-23-2021

C# Answers by Framework

Browse Popular Code Answers by Language