
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How do you do a deep copy of an object in .NET?
Deep copies duplicate everything. A deep copy of a collection is two collections with all of the elements in the original collection duplicated
Deep Copy is used to make a complete deep copy of the internal reference types.
In another words a deep copy occurs when an object is copied along with the objects to which it refers
Example
class DeepCopy { public int a = 10; } class Program { static void Main() { //Deep Copy DeepCopy d = new DeepCopy(); d.a = 10; DeepCopy d1 = new DeepCopy(); d1.a = d.a; Console.WriteLine("{0} {1}", d1.a, d.a); // 10,10 d1.a = 5; Console.WriteLine("{0} {1}", d1.a, d.a); //5,10 Console.ReadLine(); } }
Output
10 10 5 10
- Related Articles
- How would you deep copy an Object in Javascript?
- How do you copy a list in Java?
- How do you calculate Net Current Assets Turnover?
- How do you make a shallow copy of a list in Java?
- How do you copy a Lua table by value?
- How do you compare Python objects with .NET objects?
- How do you copy an element from one list to another in Java?
- How do you find a MongoDB record that is two level deep?
- How do I copy a file in python?
- How do you declare an interface in C++?
- How do you empty an array in C#?
- How do you make an array in Python?
- How do you create a date object from a date in Swift xcode?
- How do we copy objects in java?
- How do I copy a binary file in Python?

Advertisements