When I do the following.. anything done to Person b modifies Person a (I thought doing this would clone Person b from Person a). I also have NO idea if changing Person a wil
Is there a way to shortcut this at all?
No, not really. You'll need to make a new instance in order to avoid the original from affecting the "copy". There are a couple of options for this:
If your type is a struct
, not a class
, it will be copied by value (instead of just copying the reference to the instance). This will give it the semantics you're describing, but has many other side effects that tend to be less than desirable, and is not recommended for any mutable type (which this obviously is, or this wouldn't be an issue!)
Implement a "cloning" mechanism on your types. This can be ICloneable
or even just a constructor that takes an instance and copies values from it.
Use reflection, MemberwiseClone, or similar to copy all values across, so you don't have to write the code to do this. This has potential problems, especially if you have fields containing non-simple types.