clone

J

James C. Li

why implement icloneable which seems to involve writing
public object Clone()
{
return this;
}

when I can do
myobject o1 = new myobject()
myobject o2;

o2 = o1;


Jason,

That's the wrong way to implement a Clone method. Your code simply
returns a reference to an existing object.

Here's an example of how to clone an object:
http://groups.google.com/groups?q="object+clone"+group:*.dotnet.*
&hl=en&lr=lang_en&ie=UTF-8&oe=UTF-
8&scoring=d&selm=3e89c582%240%2449109%24e4fe514c%40news.xs4all.nl&rnu
m=7


See the "Cloning Objects" section in this article:
http://msdn.microsoft.com/msdnmag/issues/02/06/Instincts/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top