简体   繁体   中英

copying dictionary doesn't give me expected result

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

您需要深层复制

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM