Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How would one do a deep copy in .NET?

Answer Posted / bhagyesh

class A
{
public A()
{
};
public int i;
}
class TestPerson
{
static void Main()
{
A a = new A();
A b;
a.i =5;
b=a; // not a deep copy
b.i = a.i+6;
}
}
here a.i=11 and b.i = 11 because a and b both refer same
instance of object
Deep copy would be implemented in c# using copy construction
class A
{
public A()
{
};
public A(A previouscopy)
{
i = previouscopy.i;
};
public int i;
}
class TestPerson
{
static void Main()
{
A a = new A();
a.i =5;
// Create another new object, copying a.
A b = new A(a); // Deep copy using copy constructor
b.i = a.i+6;
}
}
here a.i=5 and b.i = 11 because a and b both refer it's own
instance of object

Is This Answer Correct ?    12 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we have multiple web config files for an asp.net application?

985


What is the postback property in asp.net?

996


What is Model-View-View Model?

1028


What is the parent class of all web server control?

1039


What are validators and list some validators of asp.net?

973


How many types of validation are there?

971


What are the different method of navigation in asp.net?

1037


What are the different kinds of assemblies?

944


Which protocol is used to call a web service?

1057


Name the namespace which is used by ado.net?

964


How do you sign out from forms authentication?

1066


What is full trust in asp.net?

1096


Can we set which type of comparison we want to perform by the CompareValidator control?

1035


What are sql notifications and sql invalidations?

952


What is the purpose of master page?

916