Vincent,
Performance will differ between classes since, amongst other things, the
implementation of their constructors and Clone methods will differ. That
said, for most classes, instantiating a new object should be faster than
cloning. The only generalized exception to this is when both objects do
need to have the same data and retrieving this data from a source other than
the potentially cloneable object is quite expensive (e.g.: a slow-running
database query).
In general, you should be using cloning very rarely (i.e.: only when cloning
is what you really need to do). If you just need to create a new object
that will happen to be similar to an existing object, there's no compelling
reason to using cloning.
Also, you should be aware that a Clone method might not really be performing
what you might consider to be "cloning". If the object implements the
ICloneable interface, it should, but even that's no guarantee. Before you
even consider using cloning, I'd recommend you at least read up on the
ICloneable interface and the MemberwiseClone method of the Object class.
HTH,
Nicole
"Vincent" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@phx.gbl...
Thank you. I have one more question. Is Clone() method the
same as create a new instance. Someone says clone() is
much faster than doing new(). Why and when should I use
clone() and new().
Thanks again.
A guy who want to learn.
Vincent
-----Original Message-----
Vincent,
The Clone() method is supposed to create a copy (although
any given classmay implement it somewhat differently than you might
expect), which shouldend up being a separate object with the same attributes
and/or state as theoriginal object. The "clonedObject = originalObject"
does not create acopy. Instead, both variables end up as references to
the same object.
HTH,
Nicole
"Vincent" <ll**@hotmail.com> wrote in message
news:0b****************************@phx.gbl... Hey, I have a problem to understand the underlaying of
clone method. Hope someone can help me out.
Let's say,
clonedObject = originalObject.clone()
(syntax may be wrong, but you know what I mean, I hope )
Why can't I just do this, instead?
clonedObject = originalObject
Any comment is more than welcome.
Thanks in advance.
Vincent
.