I would like to make a program which can handle ArrayList in ArrayList so it is able to simulate 2D dynamic Array, it is ok but I have a problem when I would like to do shallow copy in my ArrayList inside ArrayList.
Here is my program:
ArrayList AA = new ArrayList();
ArrayList temp = new ArrayList();
temp.Add("hello");
AA.Add((ArrayList)temp.Clone());
Console.WriteLine(((ArrayList)AA[0])[0]);//will show "hello"
ArrayList newAA = new ArrayList();
newAA = (ArrayList)AA.Clone();
Console.WriteLine(((ArrayList)newAA[0])[0]);//will show "hello"
//now change the newAA
((ArrayList)(newAA[0]))[0] = "world";
Console.WriteLine(((ArrayList)newAA[0])[0]);//will show "world"
//AA should not change into "world" also, but it is changed
Console.WriteLine(((ArrayList)AA[0])[0]);//will show "world"
Anyone can help?
Sincerely Yours,
Pujo
Here is my program:
ArrayList AA = new ArrayList();
ArrayList temp = new ArrayList();
temp.Add("hello");
AA.Add((ArrayList)temp.Clone());
Console.WriteLine(((ArrayList)AA[0])[0]);//will show "hello"
ArrayList newAA = new ArrayList();
newAA = (ArrayList)AA.Clone();
Console.WriteLine(((ArrayList)newAA[0])[0]);//will show "hello"
//now change the newAA
((ArrayList)(newAA[0]))[0] = "world";
Console.WriteLine(((ArrayList)newAA[0])[0]);//will show "world"
//AA should not change into "world" also, but it is changed
Console.WriteLine(((ArrayList)AA[0])[0]);//will show "world"
Anyone can help?
Sincerely Yours,
Pujo