🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.csharpbuilder.language.csharp
Article #693

ArrayList inside ArrayList clone problem

#693
From: Pujo Aji
Date: Mon, 01 Nov 2004 07:21
25 lines
1847 bytes
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
Technical Details
Message-ID: <4185e412@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!wns13feed!worldnet.att.net!204.71.34.3!newsfeed.cwix.com!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,79070386737afa4f,start
X-Google-Attributes: gid1efe35,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Pujo Aji" <ajikoe@yahoo.com>
From: "Pujo Aji" <ajikoe@yahoo.com>
Newsgroups: borland.public.csharpbuilder.language.csharp
Subject: ArrayList inside ArrayList clone problem
Date: Mon, 1 Nov 2004 08:21:56 +0100
Lines: 27
Organization: TU GRAZ
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 193.171.243.75
Message-ID: <4185e412@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1099293714 193.171.243.75 (31 Oct 2004 23:21:54 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!wns13feed!worldnet.att.net!204.71.34.3!newsfeed.cwix.com!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail