Skip to main content
added 1 character in body
Source Link
marc_s
  • 759.9k
  • 186
  • 1.4k
  • 1.5k

You need to clone them somehow. Either implement ICloneable interface and do all rewriting manually or you can use some hacks/tricks like serializing and deserializing object.

Flow with serialization is something like this:

  1. Take your object
  2. Serialize it to, for example, JSON, binnarybinary format etc.
  3. Now deserialize what you got in step 2 into new object

You'll have a copy of your object that way but it costs more processing power and is prone to some hard to catch errors. But it's an easy way to go. Thing with implementing ICloneableICloneable is more reliable but you need to write all that mapping by yourself.

Also, consider using structs instead of classes. Structs are always copied by value not reference. It has some drawbacks so it's up to you if they suit your usage scenario.

You need to clone them somehow. Either implement ICloneable interface and do all rewriting manually or you can use some hacks/tricks like serializing and deserializing object.

Flow with serialization is something like this:

  1. Take your object
  2. Serialize it to, for example, JSON, binnary format etc.
  3. Now deserialize what you got in step 2 into new object

You'll have a copy of your object that way but it costs more processing power and is prone to some hard to catch errors. But it's an easy way to go. Thing with implementing ICloneable is more reliable but you need to write all that mapping by yourself.

Also, consider using structs instead of classes. Structs are always copied by value not reference. It has some drawbacks so it's up to you if they suit your usage scenario.

You need to clone them somehow. Either implement ICloneable interface and do all rewriting manually or you can use some hacks/tricks like serializing and deserializing object.

Flow with serialization is something like this:

  1. Take your object
  2. Serialize it to, for example, JSON, binary format etc.
  3. Now deserialize what you got in step 2 into new object

You'll have a copy of your object that way but it costs more processing power and is prone to some hard to catch errors. But it's an easy way to go. Thing with implementing ICloneable is more reliable but you need to write all that mapping by yourself.

Also, consider using structs instead of classes. Structs are always copied by value not reference. It has some drawbacks so it's up to you if they suit your usage scenario.

Replaced Polish link with the English version of the Microsoft page.
Source Link

You need to clone them somehow. Either implement ICloneableICloneable interface and do all rewriting manually or you can use some hacks/tricks like serializing and deserializing object.

Flow with serialization is something like this:

  1. Take your object
  2. Serialize it to, for example, JSON, binnary format etc.
  3. Now deserialize what you got in step 2 into new object

You'll have a copy of your object that way but it costs more processing power and is prone to some hard to catch errors. But it's an easy way to go. Thing with implementing ICloneable is more reliable but you need to write all that mapping by yourself.

Also, consider using structs instead of classes. Structs are always copied by value not reference. It has some drawbacks so it's up to you if they suit your usage scenario.

You need to clone them somehow. Either implement ICloneable interface and do all rewriting manually or you can use some hacks/tricks like serializing and deserializing object.

Flow with serialization is something like this:

  1. Take your object
  2. Serialize it to, for example, JSON, binnary format etc.
  3. Now deserialize what you got in step 2 into new object

You'll have a copy of your object that way but it costs more processing power and is prone to some hard to catch errors. But it's an easy way to go. Thing with implementing ICloneable is more reliable but you need to write all that mapping by yourself.

Also, consider using structs instead of classes. Structs are always copied by value not reference. It has some drawbacks so it's up to you if they suit your usage scenario.

You need to clone them somehow. Either implement ICloneable interface and do all rewriting manually or you can use some hacks/tricks like serializing and deserializing object.

Flow with serialization is something like this:

  1. Take your object
  2. Serialize it to, for example, JSON, binnary format etc.
  3. Now deserialize what you got in step 2 into new object

You'll have a copy of your object that way but it costs more processing power and is prone to some hard to catch errors. But it's an easy way to go. Thing with implementing ICloneable is more reliable but you need to write all that mapping by yourself.

Also, consider using structs instead of classes. Structs are always copied by value not reference. It has some drawbacks so it's up to you if they suit your usage scenario.

added 255 characters in body
Source Link
Vir
  • 652
  • 3
  • 10

You need to clone them somehow. Either implement ICloneable interface and do all rewriting manually or you can use some hacks/tricks like serializing and deserializing object.

Flow with serialization is something like this:

  1. Take your object
  2. Serialize it to, for example, JSON, binnary format etc.
  3. Now deserialize what you got in step 2 into new object

You'll have a copy of your object that way but it costs more processing power and is prone to some hard to catch errors. But it's an easy way to go. Thing with implementing ICloneable is more reliable but you need to write all that mapping by yourself.

Also, consider using structs instead of classes. Structs are always copied by value not reference. It has some drawbacks so it's up to you if they suit your usage scenario.

You need to clone them somehow. Either implement ICloneable interface and do all rewriting manually or you can use some hacks/tricks like serializing and deserializing object.

Flow with serialization is something like this:

  1. Take your object
  2. Serialize it to, for example, JSON, binnary format etc.
  3. Now deserialize what you got in step 2 into new object

You'll have a copy of your object that way but it costs more processing power and is prone to some hard to catch errors. But it's an easy way to go. Thing with implementing ICloneable is more reliable but you need to write all that mapping by yourself.

You need to clone them somehow. Either implement ICloneable interface and do all rewriting manually or you can use some hacks/tricks like serializing and deserializing object.

Flow with serialization is something like this:

  1. Take your object
  2. Serialize it to, for example, JSON, binnary format etc.
  3. Now deserialize what you got in step 2 into new object

You'll have a copy of your object that way but it costs more processing power and is prone to some hard to catch errors. But it's an easy way to go. Thing with implementing ICloneable is more reliable but you need to write all that mapping by yourself.

Also, consider using structs instead of classes. Structs are always copied by value not reference. It has some drawbacks so it's up to you if they suit your usage scenario.

Source Link
Vir
  • 652
  • 3
  • 10
Loading