.NET Hashtable clone

Posted by thelost on Stack Overflow See other posts from Stack Overflow or by thelost
Published on 2010-04-14T07:34:49Z Indexed on 2010/04/14 7:43 UTC
Read the original article Hit count: 291

Filed under:
|
|

Given the following code:

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;

Why does the value within the array change from 1 to 2 in the "main" Hashtable, as the change was made on a clone ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about hashtable