cloning - Fastest Way to do Shallow Copy in C# -


i wonder fastest way shallow copying in c#? know there 2 ways shallow copy:

  1. memberwiseclone
  2. copy each field 1 one (manual)

i found (2) faster (1). i'm wondering if there's way shallow copying?

this complex subject lots of possible solutions , many pros , cons each. there wonderful article here outlines several different ways of making copy in c#. summarize:

  1. clone manually
    tedious, high level of control.

  2. clone memberwiseclone
    creates shallow copy, i.e. reference-type fields original object , clone refer same object.

  3. clone reflection
    shallow copy default, can re-written deep copy. advantage: automated. disadvantage: reflection slow.

  4. clone serialization
    easy, automated. give control , serialization slowest of all.

  5. clone il, clone extension methods
    more advanced solutions, not common.


Comments