Object Cloning

Structures and classes have some fundamental differences. One important difference is that structures support copy-on-assignment, whereas classes do not. Thus classes lack automatic support for making a copy of an object. You must decide whether you want to add explicit object cloning support on a class-by-class basis.

When you want to create a class that supports object cloning, you must provide a custom instance method that is responsible for producing a copy of the current object. By convention, this method should be named Clone and its containing class should explicitly implement the ICloneable interface to advertise the fact that its objects support cloning. Listing 10.6 shows an example of a class named Dog that supports ...

Get Building Applications and Components with Visual Basic .NET now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.