如何将字典的内容复制到C#的新字典? [英] How do I copy the content of a dictionary to an new dictionary in C#?
本文介绍了如何将字典的内容复制到C#的新字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何复制词典<字符串,字符串>
另一个新字典<字符串,字符串>
等等他们是不是同一个对象?
解决方案
假设你的意思是你想他们是单个对象,而不是相同的参考对象:
词典<字符串,字符串> D =新词典<字符串,字符串>();
&字典LT;字符串,字符串> D2 =新词典<字符串,字符串>(四)
,使他们不都是同一个对象。
块引用>
模糊比比皆是 - 如果你真的想他们是同一个对象的引用:
词典<字符串,字符串> D =新词典<字符串,字符串>();
&字典LT;字符串,字符串> D2 = D;
(更改为
D
或D 2
后上面会影响双方)How can I copy a
Dictionary<string, string>
to anothernew Dictionary<string, string>
so that they are not the same object?解决方案Assuming you mean you want them to be individual objects, and not references to the same object:
Dictionary<string, string> d = new Dictionary<string, string>(); Dictionary<string, string> d2 = new Dictionary<string, string>(d);
"so that they dont are same object."
Ambiguity abound - if you do actually want them to be references to the same object:
Dictionary<string, string> d = new Dictionary<string, string>(); Dictionary<string, string> d2 = d;
(Changing either
d
ord2
after the above will affect both)这篇关于如何将字典的内容复制到C#的新字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文