Not signed in (Sign In)

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.


    • CommentAuthorgilray
    • CommentTimeNov 2nd 2006
     
    Hi Friends,
    Please tell me How to use copy constructor in C#? Is it related to Deep Copy and Swallow copy and is there any thing called IClonable? Pls reply to it.
  1.  
    All reference type objects are allocated on heap. Allocating objects on stack in not possible just like C++. When you assign one reference to another, the reference gets copied not the object. In that case both will point to the same reference.

    For example, in the following code both o1 and o2 are referring to same object.

    Object o1 = new Object();
    Object o2 = o1;

    If you want to make a copy an instance, you will have to use cloning techniques.

    Hence proved, there is no copy constructor in C#.
    • CommentAuthorgilray
    • CommentTimeNov 2nd 2006
     
    Thanks for ur reply. But i came to know that there is something called IClonable which fulfils the Copy constructor work in C#. Do u have any idea abt this?