That will not create a copy, it will simply reference the sally variable to point to the same object as roger variable. Try this to see what result you get:
Dim same As Boolean = sally Is roger
To provide cloning you have to write code to do that yourself (ie create object and copy the data), the standarized way to do this is to have your class implement
ICloneable Interface (System) and perform your actions in the Clone method, here the simplest solution is to use the protected
Object.MemberwiseClone Method (System) that all object have inherently. Here is a sample Person class that is clonable (shallow):
Public Class Person
Implements ICloneable
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Function Clone() As Object Implements System.ICloneable.Clone
Return Me.MemberwiseClone
End Function
End Class
Example usage:
Dim p1 As New Person
p1.Name = "Sally"
Dim p2 As Person = CType(p1.Clone, Person)
See what Name the Person object in p2 variable has. Also now try this:
Dim same As Boolean = p1 Is p2
If you didn't catch the "same" point; two different object instances are not the same. When you create copy of an object (clone) you have a new object that is not the same as the original, even if it contains the same data.