Creating a copy of an object in C# [duplicate]
Possible Duplicate: How do you do a deep copy an object in .Net (C# specifically)? Please have a look at the code below (excerpt from a C# book): namespace Example { class MyClass { public int val; } struct myStruct { public int val; } class Program { static void Main(string[] args) { MyClass objectA = new MyClass(); MyClass objectB = objectA; objectA.val = 10; objectB.val = 20; myStruct structA = new myStruct(); myStruct structB = structA; structA.val = 30; structB.val = 40; Console.WriteLine("objectA.val = {0}", objectA.val); Console.WriteLine("objectB.val = {0}", objectB.val); Console