Object MemberwiseClone Method


Public Class PersonID
    Public IdNumber As Integer
    Public Sub New(IdNumber As Integer)
        Me.IdNumber = IdNumber
    End Sub
End Class ' PersonID




Public Class Person
    Implements ICloneable
    Public ID As PersonID
    Public Age As Integer
    Public Name As String
    Public Function Clone() As Object Implements ICloneable.Clone
        Return Me.CreateDeepCopy(CreateShallowCopy())
    End Function
    Friend Function CreateShallowCopy() As Person
        Return CType(Me.MemberwiseClone(), Person)
    End Function
    Friend Function CreateDeepCopy(current As Person) As Person
        Return current
    End Function
End Class


References:

MSND Reference

Comments

Popular posts from this blog

مقدمة الي تشفير الحروف الأبجدية العربية

VB.NET Translucent Control using GDI+

Add Custom Event to a Class in VB.NET