Create a copy of a nested Dictionary

cerobledo
cerobledo used Ask the Experts™
on
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

thanks

Chuck
Comment
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

Commented:
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.

thanks

cerobledo

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