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/
 
Back
Top