I’m in need of some remedial instruction collections of objects. I doubt if
this question is specific to pocket pc and VB, but that’s where I’m coding.
When I create a collection, call it collection A, and then create a new
collection B, if I make a change to one of the items in collection B, the
exact same changes effect collection A. While I could see this as being a
feature, for what I’m doing… well, I wish it wouldn’t. Is there some simple
way that I can “sever” the linkage between these two collections?
Here’s an example of the problem
Dim Vegetables As New Collection
Dim NewVegetables As New Collection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
LoadVeggies()
NewVegetables = Vegetables
Dim Vegetable0 As New Vegetable
For Each Vegetable0 In NewVegetables
If Vegetable0.Name = "Squash" Then
Vegetable0.Color = "Green"
End If
Next
End Sub
Private Sub LoadVeggies()
Dim vegetableA As New Vegetable
vegetableA.Name = "Carrot"
vegetableA.Color = "Orange"
Vegetables.Add(vegetableA)
Dim vegetableB As New Vegetable
vegetableB.Name = "Squash"
vegetableB.Color = "Yellow"
Vegetables.Add(vegetableB)
End Sub
End Class
In this code, when I set a brake pt at the end sub for the Form 1 load, I’d
like to see the If logic create only a green Squash in NewVegetables. The
Yellow Squash should stay in Vegetables. It doesn’t, I get a green squash in
both collections. Some how the two collections are linked and I need to
sever the link. Suggestions?