views:

76

answers:

2

I have to copy one dictionary, work with that copy and return to the original one.

What seems to happen is that the orignal dictionary is modified when I do some work on the copied one.

Here is my code :

dmodified_profile = new SortedDictionary<int,SortedDictionary<string,List<string>>>(d_profile);

I don't know why d_profile which is the original one could be modified if my modifications are done on the dmodified_profile dictionary ?

Thanks

+5  A: 

You need to deep copy.

Alex Brasetvik
+2  A: 

Your SortedDictionary maps an integer to a REFERENCE to another SortedDictionary. When you copy that dictionary you copy the values of the keys as well as the REFERENCEs of the values, because your dictionary's value is of a reference type.

Ciwee