Thursday, July 1, 2010

SHALLOW CLONE USING ICLONEABLE INTERFACE

A shallow copy creates a new instance of the same type as the original
object, and then copies the non-static fields of the original object. If the
field is a value type, a bit-by-bit copy of the field is performed.

Example Programe
using System;
public class one
{public int a;}
public class two:ICloneable
{
public int b;
public one o=new one();
public two(int a1,int b1)
{
o.a=a1;
b=b1;
}
public void show(){Console.WriteLine(o.a+" "+b);}
public Object Clone()
{
return (this.MemberwiseClone());
}
}
class tth
{
public static void Main(string[] args)
{
two t1=new two(1,2);
two t2=(two)t1.Clone();
t1.show();
t2.show();
t1.o.a=5;
t1.b=5;
t1.show();
t2.show();
}
}

No comments:

Post a Comment