1

I have strongly typed class,

Public Class RowData

    Sub New(ByVal rRecord As String, ByVal rAccount As String, _
            ByVal soExperian As Boolean, ByVal soEquifax As Boolean, ByVal soTransunion As Boolean, _
            ByVal snExperian As Boolean, ByVal snEquifax As Boolean, ByVal snTransunion As Boolean)

        Me.Record = rRecord
        Me.Account = rAccount
        Me.oExperian = soExperian
        Me.oEquifax = soEquifax
        Me.oTransunion = soTransunion
        Me.nExperian = snExperian
        Me.nEquifax = snEquifax
        Me.nTransunion = snTransunion

    End Sub

.........

End Class

Then I use the following code to declare 2 elements array.

Dim Tradelines(1) As List(Of RowData)

Tradelines(0) = New List (Of RowData)
Tradelines(0).Add(New RowData("222", "222", False, False, False, False, False, False))

Tradelines(0) is populated, no problems, but when I use the following code to copy Element-0 to Element-1 they seem to be bound so that if I change any value in either element, the other element updates automatically. I do not want that, any clue?

Tradelines(1) = Tradelines(0)
Shai
  • 25,159
  • 9
  • 44
  • 67

2 Answers2

1

The items in your collections of type RowData are passed by reference, they are not value types. That's why changing one, will make changes in all collections the item is added, because it's the same object.

You need to create new objects and add them to the new collection if you don't want the same references. One way to this in a good way is to implement IClonable in your RowData class.

Tradelines(1) = Tradelines(0).Clone()
Tomislav Markovski
  • 12,331
  • 7
  • 50
  • 72
  • The `Clone()` function is then available for sub items only meaning I can do, `Tradelines(1)(0) = Tradelines(0)(0).Clone` to copy first sub item in element-0 only, but I did something recursive and everything now works great, Thanks! – xShareMaster Dec 27 '11 at 10:36
0

try this

Tradelines(0).ForEach(AddressOf Tradelines(1).Add)