Member Wise Clone : Clone « Class « VB.Net






Member Wise Clone

Member Wise Clone
Imports System
Imports System.Collections


Public Class MainClass

  Shared Sub Main()
        Dim anArray() As String = {"www.java2s.com"}
        Dim a As New CloneableObject(anArray)

        a.DisplayData()
        Dim b As CloneableObject
        b = a.Clone()
        Dim newData As String = "New Data"
        b.ChangeData(newData)

        b.DisplayData()

        a.DisplayData()
  End Sub
  
End Class

Public Class CloneableObject
    
    Private m_Data() As String
    
    Public Sub New(ByVal anArray() As String)
        m_Data = anArray
    End Sub
    
    Public Sub DisplayData()
        Dim temp As String
        For Each temp In m_Data
            Console.WriteLine(temp)
        Next
    End Sub
    
    Public Sub ChangeData(ByVal newData As String)
        m_Data(0) = newData
    End Sub
    
    Public Function Clone() As CloneableObject
        Return CType(Me.MemberwiseClone, CloneableObject)
    End Function
End Class

           
       








Related examples in the same category

1.Clonable ObjectClonable Object