Re: arraylist copy
- From: J L <john@xxxxxxxxxxxxx>
- Date: Fri, 08 Apr 2005 15:38:58 -0700
What does "shallow" and "deep" copy mean?
TIA,
John
On Fri, 8 Apr 2005 19:50:50 +0200, "Herfried K. Wagner [MVP]"
<hirf-spam-me-here@xxxxxx> wrote:
>"Sam" <samuel.berthelot@xxxxxxxx> schrieb:
>> Dim rNodeList As New ArrayList
>> Dim rNodeListNew As New ArrayList
>>
>> For iCntr As Integer = 0 To tvRelations.Nodes.Count - 1
>> rNodeList.Add(tvRelations.Nodes(iCntr).Text)
>> Next
>>
>> rNodeListNew = rNodeList
>> rNodeList.RemoveAt(2)
>>
>> after I've filled rNodeList, it contains 8 elements.
>> So does rNodeListNew
>>
>> But when I remove the element 2 of rNodeList, it is also removed in
>> rNodeListNew. Why ? Do they both point to the same memory location ?
>> How can I prevent that in vb ?
>
>Both variables point to the same instance of 'ArrayList'. You can use the
>arraylist's 'Clone' method to create a shallow copy of the arraylist:
>
>\\\
>Dim al1 As New ArrayList
>al1.Add("Bla")
>al1.Add("Goo")
>Dim al2 As ArrayList = al1.Clone()
>al1.Clear()
>MsgBox(CStr(al2.Count))
>///
.
- Follow-Ups:
- Re: arraylist copy
- From: Cor Ligthert
- Re: arraylist copy
- From: Herfried K. Wagner [MVP]
- Re: arraylist copy
- References:
- arraylist copy
- From: Sam
- Re: arraylist copy
- From: Herfried K. Wagner [MVP]
- arraylist copy
- Prev by Date: Re: Excaping recursive functions
- Next by Date: Re: Emailing CheckBoxList content
- Previous by thread: Re: arraylist copy
- Next by thread: Re: arraylist copy
- Index(es):
Relevant Pages
|
Loading