473,498 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to clone a collection?

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
Nov 21 '05 #1
2 8119
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

"phx" <hd****@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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

Nov 21 '05 #2
phx
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.

"Stephen Muecke" <st*****@senet.com.au> wrote in message
news:Ol**************@TK2MSFTNGP11.phx.gbl...
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

"phx" <hd****@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2652
by: Jason Evans | last post by:
Hi All, I am writing my own implementation of queue via a linked list, note not a LinkedList, and was running into trouble with the clone method. I was wondering if anyone could point out some...
1
1295
by: Jeff Haumesser | last post by:
I have a Collection called Grooming. Each object in this collection contains the property GroomingServices of type Collection. I also have a Clone of this Groomings collection called GroomingsInit....
8
3810
by: Noozer | last post by:
I'm looking for a way to generate a "clone" of an object. Right now I need to write a Clone function for every class that make and I'd like to have a generic routine. Instead of doing this: For...
2
11447
by: Steven | last post by:
Hi, I have created my own node (class MyNode : TreeNode) for a TreeView. To populate the treeview, i use something like MyNode newNode = new MyNode("Bla bla bla","0","1") for example. But, to...
1
4381
by: Neeraj | last post by:
hi I want to make clone of current Form which is currently seen.I Used attribute above the class declaration which extends Form. Impleament the ICloneable interface and Make method which code is...
16
2477
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some...
14
8564
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event...
7
2798
by: =?Utf-8?B?Sm9lbCBNZXJr?= | last post by:
I have created a custom class with both value type members and reference type members. I then have another custom class which inherits from a generic list of my first class. This custom listneeds...
14
3885
by: Ste | last post by:
Good morning, what can be the best way to clone an object with events ? This because I have made a deep copy of my object and added new event handlers but events are fired from the original...
0
7126
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4916
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3087
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
293
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.