熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

VB.NET中對象的克隆[2]

2013-11-13 12:15:18  來源: .NET編程 

  Public Property Name() As String

    Get

        Return m_Name

    End Get

    Set(ByVal NewName As String)

        m_Name = NewName

    End Set

  End Property


  Public Function Clone() As CResume

    Dim BF As New BinaryBinaryFormatter()

    Dim MS As New MemoryStream()

    BFSerialize(MS Me)

    MSPosition =

    Return (CType(BFDeserialize(MS) CResume))

  End Function

End Class

  在Form裡面可以這樣調用

  Dim Resume As New CResume()

  Dim Resume As New CResume()

    ResumeName = AAA

    ResumeAddress = office:smarttags />ShanghaiChina

    Resume = ResumeClone()

    ResumeName = BBB

    ResumeAddress = BeijingChina

    DebugWriteLine(ResumeName)     依然是AAA

    DebugWriteLine(ResumeAddress)    

  總結主要調用了VBNET的流和序列化技術使得對象的克隆免去了繁瑣的讀寫操作也簡化了代碼

[]  []  


From:http://tw.wingwit.com/Article/program/net/201311/15511.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.