Jaro said:
I did it, but if use in function 'return me' I've still have
references... I'm totally newbie in .net
have you a little piece od code how to do it?
You must not write "return me", you have to return the object created in the
Clone method that implements ICloneable.Clone. Here is an example:
Public Class Class1
Implements ICloneable
Public Value1 As Integer
Public Value2 As Class2
Public Function Clone() As Object Implements System.ICloneable.Clone
Dim Result As Class1
Result = New Class1
Result.Value1 = Me.Value1
Result.Value2 = DirectCast(Me.Value2.Clone, Class2)
Return Result
End Function
End Class
Public Class Class2
Implements ICloneable
Public Value1 As Byte
Public Function Clone() As Object Implements System.ICloneable.Clone
Dim Result As Class2
Result = New Class2
Result.Value1 = Me.Value1
Return Result
End Function
End Class
This example also shows how to handle reference types. A class is a
reference type whereas an Integer and Byte is a value type. You can simply
copy a reference type by assigning the variable to another variable (see
Result.Value1 = Me.Value1). To copy an object that is a refernce type, you
must also call it's clone method because a simple assignment (like
result.value2 = me.value2) would only copy the reference to the same object
but not the object itself.