Copy of a variable instead of referenc to it?

  • Thread starter Thread starter Özden Irmak
  • Start date Start date
Ö

Özden Irmak

Hi,

I want to make a copy of a variable (which is a type of a custome class)
instead of referencing it...

MyClass MyCopy = MyOriginal

creates a reference and if I make a change on lets say on a property on
MyCopy, the property on MyOriginal does also change...

Any help?

Thanks in advance,

Özden
 
Özden Irmak said:
Hi,

I want to make a copy of a variable (which is a type of a custome
class) instead of referencing it...

MyClass MyCopy = MyOriginal

creates a reference and if I make a change on lets say on a property
on MyCopy, the property on MyOriginal does also change...

Any help?

This class should implement the "IClonable" interface...
If now, you have to implement the "Clone" by hand...
But then you can only "copy" the public members/properties...

And you should decide if you want a shallow-copy or a deep-copy...


For more info see:
An insight into cloning objects in .NET
http://www.codeproject.com/dotnet/Clone.asp


An other way is to serialize and the deserialize the object. But for
this the object must allow "serialization" (SerializableAttribute).




--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp


Do you need daily reports from your server ?
http://sourceforge.net/projects/srvreport/
 
Jochen,

Thank you very much...:)

Özden

Jochen Kalmbach said:
This class should implement the "IClonable" interface...
If now, you have to implement the "Clone" by hand...
But then you can only "copy" the public members/properties...

And you should decide if you want a shallow-copy or a deep-copy...


For more info see:
An insight into cloning objects in .NET
http://www.codeproject.com/dotnet/Clone.asp


An other way is to serialize and the deserialize the object. But for
this the object must allow "serialization" (SerializableAttribute).




--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp


Do you need daily reports from your server ?
http://sourceforge.net/projects/srvreport/
 

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

Back
Top