[Mono-list] Making a copy of a class instance

Ben Motmans Ben Motmans <ben.motmans@gmail.com>
Tue, 25 Jan 2005 17:53:49 +0100


IClonable interface
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemicloneableclasstopic.asp

implement the interface in your class, so you can do
myClass c1 = new myClass();
myClass c2 = c1.Clone();


On Tue, 25 Jan 2005 10:46:47 -0600, Sergio Duran <sergioduran@gmail.com> wrote:
> Hi everybody,
> 
> I want to make a copy of class instance, but I know classes are
> asigned by reference, so doing
> 
> myClass class1=new Class();
> myClass class2=class1;
> 
> is the same as working with pointers, and class2 becomes an alias of
> class1, I want to make class2 an independent copy of class1, and be
> able to change values in each one of the instance and not touching the
> other instance.
> 
> I'm thinking about doing a myClass ctor with a myClass argument and
> manually copy every variable of the source instance, to the new
> instance, but I dont think that's the best aproach.
> 
> isnt there a myClass class2=duplicate class1?
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>