arraylist副本

编程入门 行业动态 更新时间:2024-10-28 00:27:41
本文介绍了arraylist副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下代码: Dim rNodeList As New ArrayList Dim rNodeListNew作为新的ArrayList 对于iCntr As Integer = 0到tvRelations.Nodes.Count - 1 rNodeList.Add(tvRelations.Nodes(iCntr).Text) 下一页 rNodeListNew = rNodeList rNodeList.RemoveAt(2) 在我填充了rNodeList之后,它包含了8个元素。 rNodeListNew是这样的 但是当我删除rNodeList的元素2时,它也会被删除在 rNodeListNew。为什么?它们都指向相同的内存位置吗? 如何在vb中阻止它? Thx

Hi, I have the following code : 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 ? Thx

推荐答案

2005年4月8日 将行rNodeListNew = rNodeList切换为: rNodeList.CopyTo(rNodeListNew) 这应该将对象复制到新的arraylist中。这样, arraylists不会指向相同的对象。如果你使用.Clone方法 那么两个arraylists仍将指向相同的对象。 HTH Joseph MCAD " Sam" < SA ************** @ voila.fr>在消息中写道 news:11 ********************** @ o13g2000cwo.googlegr oups ... April 8, 2005 Switch the line rNodeListNew = rNodeList to: rNodeList.CopyTo(rNodeListNew) This should COPY the objects into the new arraylist. This way the arraylists do not point to the same objects. If you use the .Clone method then both arraylists will still point to the same objects. HTH Joseph MCAD "Sam" <sa**************@voila.fr> wrote in message news:11**********************@o13g2000cwo.googlegr oups... 我有以下代码: Dim rNodeList As New ArrayList Dim rNodeListNew As New ArrayList 对于iCntr As Integer = 0到tvRelations.Nodes.Count - 1 rNodeList.Add(tvRelations.Nodes(iCntr).Text)下一页 rNodeListNew = rNodeList rNodeList.RemoveAt(2) 在我填充rNodeList后,它包含8个元素。 rNodeListNew 但当我删除元素2对于rNodeList,它也在 rNodeListNew中删除。为什么?它们是否都指向相同的内存位置?如何在vb中阻止它? Thx Hi, I have the following code : 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 ? Thx

尝试使用ArrayList的.Clone()方法。 Marcie 2005年4月8日09:24:51 -0700,"山姆" < SA ************** @ voila.fr>写道: Try the .Clone() method of the ArrayList. Marcie On 8 Apr 2005 09:24:51 -0700, "Sam" <sa**************@voila.fr> wrote: 我有以下代码: Dim rNodeList As New ArrayList Dim rNodeListNew As新的ArrayList 对于iCntr As Integer = 0到tvRelations.Nodes.Count - 1 rNodeList.Add(tvRelations.Nodes(iCntr).Text)下一页 rNodeListNew = rNodeList rNodeList.RemoveAt(2) 在我填充rNodeList后,它包含8个元素。 rNodeListNew <但是当我删除rNodeList的元素2时,它也会在 rNodeListNew中删除。为什么?它们是否都指向相同的内存位置?如何在vb中阻止它? Thx Hi,I have the following code :Dim rNodeList As New ArrayListDim rNodeListNew As New ArrayListFor iCntr As Integer = 0 To tvRelations.Nodes.Count - 1 rNodeList.Add(tvRelations.Nodes(iCntr).Text)NextrNodeListNew = rNodeListrNodeList.RemoveAt(2)after I''ve filled rNodeList, it contains 8 elements.So does rNodeListNewBut when I remove the element 2 of rNodeList, it is also removed inrNodeListNew. Why ? Do they both point to the same memory location ?How can I prevent that in vb ?Thx

谢谢,那确实是克隆:) thanks, that''s clone indeed :)

更多推荐

arraylist副本

本文发布于:2023-11-09 16:08:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572826.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:副本   arraylist

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!