C# – Copy a dictionary

The simplest way to make a copy of a dictionary is to use the copy constructor. You pass the dictionary you want to copy to the new dictionary’s constructor, like this: Note: If you’re using a non-default comparer, you’ll want to pass it to the copy constructor (i.e. new Dictionary(d, d.Comparer)). The copy constructor handles … Read more

C# – How to copy an object

In this article I’ll explain how to copy an object. I’ll explain the difference between shallow and deep copying, and then show multiple ways to do both approaches for copying objects. At the end, I’ll show a performance and feature comparison to help you decide which object copying method to use. Shallow copy vs Deep … Read more