Cloning Objects

Mesh_2010
Posted by Mesh_2010 under C# category on | Points: 40 | Views : 1670
[code]
public WebSite GetCopy()
{
return MemberwiseClone() as WebSite;
}

WebSite beta = new WebSite();
WebSite site5 = new WebSite();
site5.BetaSite = beta;
WebSite site6 = site5.GetCopy();
bool areSitesEqual = ReferenceEquals(site5, site6);
bool areBetasEqual = ReferenceEquals(site5.BetaSite, site6.BetaSite);
Console.WriteLine(
"Sites Equal: {0}, Betas Equal: {1}",
areSitesEqual, areBetasEqual);

Sites Equal: False, Betas Equal: True
[/code]

Comments or Responses

Login to post response