-1

What is clone object and types?can give simple example ?and is possible call clone object to List ?

saran
  • 1,253
  • 4
  • 19
  • 32

3 Answers3

3

Look here: Deep cloning objects

Community
  • 1
  • 1
alexl
  • 6,751
  • 3
  • 23
  • 29
1

A clone is a copy (i.e. a new instance). Several BCL classes implement IClonable which returns an object which should be a new instance with the values of the original.

A good sample is at:

http://msdn.microsoft.com/en-us/library/system.icloneable.aspx

I don't think List<T> supports it, but you could add it, as long as the T are IClonable.

Daniel A. White
  • 181,601
  • 45
  • 354
  • 430
0

Cloning means creating another instance of your Reference type (Anything that is not a constant [integers, chars...] or a structure) so you can modify one of them without affecting the other, as just using the Equals operator or passing one of such value types would create a pseudo-pointer.

To clone your classes, just make them implement ICloneable [http://msdn.microsoft.com/en-us/library/system.icloneable.aspx] and call the Clone() Method, casting the return type to the object type desired.

Good Luck :)

Machinarius
  • 3,467
  • 1
  • 27
  • 50