Add a Clone Function to an existing class
Public Class Person
Public FirstName As String
Public LastName As String
Public Function Clone() As Person
Return DirectCast(Me.MemberwiseClone(), Person)
End Function
End Class
' Make a Person.
Dim per1 As New Person
per1.FirstName = txtFirstName.Text
per1.LastName = txtLastName.Text
' Clone.
Dim per2 As Person = per1.Clone()
' Display the new person.
lblFirstName.Text = per2.FirstName
lblLastName.Text = per2.LastName
No comments:
Post a Comment