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 session in web technology?

927


Explain what are the advantages of asp.net mvc framework? : asp.net mvc

1060


What is boxing and unboxing in asp.net?

1039


Which is faster viewbag or viewdata?

931


How do I create a web form?

994


In the Repeater control which way you can edit?

1056


What are the advantages of Web API?

1069


Write a code snippet to implement the indentation in json in web api.

1035


What is caching in asp.net?

979


What is the size of Get method and how much data it can store?

1089


What is the difference between globalization and localization?

917


How to reduce the width of textbox in editcommandcolumn of datagrid?

962


Describe the diffeerence between inline and code behind - which is best in a loosely coupled solution?

1059


What is a session in programming?

1016


What symbol specifies the beginning of a query string?

894