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

What is the main difference between Asp.net and Vb.net?

1002


What is a viewstate?

932


Define a static class?

934


Why would anyone need to implement their own hashtable or linked list?

2887


What is caching? What are different ways of caching in asp.net?

1222


Which methods validate all the controls on a page?

921


What is difference between rest and soap?

1045


What is the difference between cookie and session?

937


How do you hide the columns?

986


How to disable disable browser's Back button in asp.net (JavaScript)?

1064


What does session_start () do?

1018


If 200 is for all successful operation then why do we have 201 response codes?

862


Define web.config in .net?

1025


How to Insert/Add in ASPXgridview

979


Define the term Web Garden?

907