I am new to C#, and I want to copy the value of one property to another. The following is the sample code I wrote:
public class MyObject
{
private MyObject()
{
intArray = new int[3]{1,2,3}
int1 = 1;
SaveCopy();
}
private void SaveCopy()
{
intArray_Copy = intArray;
int1_Copy = int1;
}
public int[] intArray { get; set; }
public int int1 { get; set; }
public int[] intArray_Copy { get; set; }
public int int1_Copy { get; set; }
}
I am writing a SaveCopy()
function to save the value of intArray
and int1
. I understand that using "=" makes a reference to the original property, once the value of the original property changes, the copy will also change. How do I make a copy that is different from the original property?