vb.net

位置:IT落伍者 >> vb.net >> 浏览文章

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


发布日期:2018年07月27日
 
VB.NET中对象的克隆[2]

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的流和序列化技术使得对象的克隆免去了繁琐的读写操作也简化了代码

[] []

               

上一篇:VB.NET循环体内的局部变量

下一篇:VB.NET中对象的克隆[1]