How to clone a collection?

  • Thread starter Thread starter phx
  • Start date Start date
P

phx

I have to collection that stores the items from the same class. I want to
copy the items of the second collection to the first one , and empty the
second.
first.clean()
first=second
second()

causes an error in the program , it seems when i clear the second one , alse
referances in the first one also empties. Anyway to clone these?
thank you
 
Public Class MyCollection
Inherits CollectionBase
Implements ICloneable

#Region " ICloneable Implementation "

Private Function IClone() As Object Implements ICloneable.Clone
'Implemented in Public Function Clone()
End Function

Public Function Clone() As MyCollection

'---------------------------------------------------------------------------
------
'Create a copy of the collection

'---------------------------------------------------------------------------
------
Dim collection As New MyCollection()
'Loop through each item and add it to the copy
Dim item As MyObject
For Each item In Me.InnerList
'Use InnerList to prevent raising events ?????
collection.InnerList.Add(eProject)
Next
'Return the copy
Return collection
End Function

#End Region

End Class
'------------------------------------------------------------------
'Clone the second collection
MyFirstCollection = MySecondCollection.Clone
'Clear the second collection
MySecondCollection.Clear

Stephen
 
thank you for your answer

i guess "collection.InnerList.Add(eProject)" command is wrong, i changed the
eproject with "item" . but made me wonder where "eproject" came from.
 
Back
Top