Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 6
    Possible third option: myObject = new MyClass(oldObject);. Though this would imply an exact copy of the original object in a new instance. Commented Jun 25, 2015 at 13:16
  • I think the new MyClass(oldObject) is the best solution for the cases where initialization is expensive. Commented Jun 25, 2015 at 15:39
  • 8
    Copy constructors are more C++ style. .NET seems to favor a Clone() method that returns a new instance that's an exact copy. Commented Jun 25, 2015 at 17:15
  • 2
    The constuctor could easily do nothing but call a public Initialize() method so you still have that single point of initialization which could be invoked an any point to effectivly create a "new" fresh object. I have used libraries which have something like an IInitialize interface for objects that can be used in object pools and reused for performance. Commented Jul 2, 2015 at 13:20