给定以下代码:
Hashtable main = new Hashtable();
Hashtable inner = new Hashtable();
ArrayList innerList = new ArrayList();
innerList.Add(1);
inner.Add("list", innerList);
main.Add("inner", inner);
Hashtable second = (Hashtable)main.Clone();
((ArrayList)((Hashtable)second["inner"])["list"])[0] = 2;
为什么数组中的值在“主”哈希表中从 1 变为 2,因为更改是在克隆上进行的?
最佳答案
您克隆了 Hashtable
,而不是它的内容。
关于c# - .NET 哈希表克隆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2635626/