Why doesn't C# support the concept of Copy Constructor?

Amit picture Amit · Apr 20, 2010 · Viewed 9.9k times · Source

I was asked this question in one of my interviews, but I wasn't able to find out exactly why this concept is not there.

Please let me know.

Answer

Jeff Sternal picture Jeff Sternal · Apr 20, 2010

It's not built into the language because there is not a reasonable default implementation.

Copy constructors suffer from many of the same ambiguities as cloning. For example, whether you want to make a shallow copy or a deep copy depends on your particular circumstances.

Say you have an Order class with a Customer property. Should its copy constructor create a new customer or point to the original instance? Probably the original instance - but what about Order.Payment?

Worse, even when you do want to perform a deep copy, you may even not be able to create all of your subordinate objects, because their constructors (or comparable factory methods) may not be accessible.

In case that's not enough, this article on Java Design Issues highlights some other problems (like type truncation).