Arraylist acting like a Linked List
Hello,
I have been working on this all day and can't tell if this is a bug or an intended funciton of an arraylist. I don't believe I have ever run into it before.
I have an arraylist defined within a function and I need to add objects to it. I pass in an object to the function, update the object's properties, and add it to the arraylist. Then I update the object's properties again and add it again to the arraylist.
The problem is: When I update the variable's properties before adding it the second time,the arraylist's first item is also updated! I don't specifically reference the arraylist's first item... it's just getting updated when I modify the original object. I can't figure out how to get around this, since I need to add multiple copies of the item from within a loop.
Here is a simplified version of the code:
=========================================
Private Sub AddItemByLargestUofM(ByVal inItem As CCartItem, ByVal inQuantityEach As Integer)
Dim ItemsToAdd As New ArrayList
Dim StartQty As Decimal
StartQty = inQuantityEach
While StartQty > 0
inItem.Quantity = StartQty
ItemsToAdd.Add(inItem) 'If I do a Watch on the ItemsToAdd here, the first Item's Quantity has changed before I add the second Item
StartQty = StartQty - 5
'Do something with ItemsToAdd
End While
End Sub
=========================================
Ihope someone can help clear this up for me. I have some other options, but they are messy (such as copying the object by copying all of it's 20 or so properties)
Thank You,
~ Michelle

