Cloning C# objects using MemberwiseClone

public CarClass GetCopy()
{
	return MemberwiseClone() as CarClass;
}
 
CarClass beta = new CarClass();
CarClass newcar = beta.GetCopy();
bool areCarsEqual = ReferenceEquals(beta, newcar);
Console.WriteLine("Are cars Equal?: {0}",areCarsEqual);

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.