I have a function that takes an object from a list as a parameter. I create a new instance of this object and make it equal to the object passed into the function. I change some of the properties of the new object, but these changes also get applied to the original object in the list. Example:
public void myFunction(Object original)
{
var copyOfObject = original;
copyOfObject.SomeProperty = 'a';
}
From reading, I guess I am creating a shallow copy of my original object, so when I update the properties on my new object this causes the properties on the original to change to? I've seen some examples of copying the entire list of objects to create a deep copy, but I only want to create a deep copy of this single object and not the entire list. Can I do this without having to do:
copyOfObject = new Object();
copyOfObject.someProperty = original.someProperty;
before making my changes?