M
Michael D. Ober
In VB 2005, the ICloneable interface requires the following:
Class foo
Implements ICloneable
Public Function Clone() as Object Implements System.ICloneable.Clone
' return new_object of type foo
End Function
End Class
However, with Option Strict On, to use this requires
newfoo as foo = CType(oldFoo.Clone(), foo)
This takes additional CPU cycles at runtime - first to coerce foo's clone to
object and then to coerce the clone back to foo.
In the case of a non-inheritable object with a Clone function, is there any
reason to use:
Class foo
Public Function Clone() as foo
' return new_object of type foo
End Function
End Class
Now you can say
option strict on
newfoo = oldFoo.Clone()
Thanks,
Mike Ober.
Class foo
Implements ICloneable
Public Function Clone() as Object Implements System.ICloneable.Clone
' return new_object of type foo
End Function
End Class
However, with Option Strict On, to use this requires
newfoo as foo = CType(oldFoo.Clone(), foo)
This takes additional CPU cycles at runtime - first to coerce foo's clone to
object and then to coerce the clone back to foo.
In the case of a non-inheritable object with a Clone function, is there any
reason to use:
Class foo
Public Function Clone() as foo
' return new_object of type foo
End Function
End Class
Now you can say
option strict on
newfoo = oldFoo.Clone()
Thanks,
Mike Ober.