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 are server side controls?

987


what are the events raised in asp.net page life cycle?in which stage view state can be loaded?

989


What is mvc in angular?

973


What is server infrastructure & server components?

1211


Why do we need master page in asp.net?

939


Differentiate between authentication and authorization.

965


Types of instancing properties and explain each. Tell the difference between multiuse,singleuse and globalmultiuse and which is default ?

2793


What is the maximum amount of memory any single process on windows can address?

1027


How does session work?

911


Can you use c# without .net?

969


What is a master page and what does it do?

924


Which is the parent class of the web server control?

1054


What is the difference between abstract class vs interface? Can give me the real time examples?

946


Explain code snippet to register exception filters from controller?

1014


How do you implement sql caching in asp.net?

1060