Collection of Collection Clone

J

Jeff Haumesser

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. The
sub-collection GroomingServices has also been cloned.

My question is:
Can I simply set Groomings = GroomingsInit? Will the sub-collection
also be set to that of the GroomingInit?

Example:
Below is a method in my clsGroomings class object.

Public Function Clone() as Object Implements ICloneable.Clone
dim GroomingsClone as new clsGroomings
dim GroomingClone as clsGrooming

For each objGrooming as clsGrooming in Me
GroomingClone = new clsGrooming
GroomingClone.BeginTime = objGrooming.BeginTime
GroomingClone.EndTime = objGrooming.EndTime
GroomingClone.objGroomingServices = objGroomingServices.Clone
GroomingsClone.Add(GroomingClone)
Next

Return GroomingsClone
End Sub

NOTE: The objGroomingServices has it's own Clone method similar to the one
above.

Thankyou for any input.

Jeff
 
C

Cor Ligthert

Jeff,

Does this sample make it clear for you?

\\\
Dim a As New ArrayList
Dim b As ArrayList
b = a
If a Is b Then _
MessageBox.Show("a and b references the same arraylist")
b = DirectCast(a.Clone, ArrayList)
if Not a Is b Then _
MessageBox.Show("we are not the same")
a.Add("Jeff")
b.Add("Cor")
MessageBox.Show("Hello " & a(0).ToString & _
" and " & b(0).ToString)
///

I hope this helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top