Create a copy of a nested Dictionary

cerobledo used Ask the Experts™
I need to make an independent copy of this data structure

Dictionary<int, Dictionary<string, string>>();

I create a copy of one of these dictionaries and when I clear it...the copy is cleared also


Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Did you use MemberwiseClone() to get a copy?
Hi Qlemo,

I appreciate the feedback but I came up with a different solution.  I just saved the same data to both dictionaries and then when the original changes, I apply the changed (different data) to my diagram.

Incidentally, I think because the dictionaries contained reference data types they required a deep copy to be independent of one another.  Even that did not work, however.  I don't think I was getting to the nested dictionary which contained the data.



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial