如何在列表中进行深层复制 [英] How to do deep copy in lists

查看:91
本文介绍了如何在列表中进行深层复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var contentItem = new List<Dictionary<string, object>>();

                foreach (var dictionary in (List<Dictionary<string, object>>)reciptDictionary["Content"])
                {
                    contentItem.Add(dictionary);
                }







像这样我使用现有列表创建一个新列表(contentItem)( reciptDictionary)。

但是在这里,当我更改contentItem中的值时,它也会更改reciptDictionary中的值。我不想那样。我希望原始列表保持不变。



有人可以告诉我怎么做。谢谢




Like this Im creating a new list (contentItem) using existing list(reciptDictionary).
But in here when I change values in contentItem it also change values in reciptDictionary. I dont want that. I want original list to remain same.

Can someone please tell me how to do this. Thanks

推荐答案

读了这个



克隆深层复制字典的最佳方法是什么? [ ^ ]



或者这个



通过序列化对象实现深度克隆 [ ^ ]


这篇关于如何在列表中进行深层复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆