This is probably an easy question, I'm pretty new to OOP in general.
If I have a simple class with one int array property (and constructor)
public class MyClass
{
public int[] MyProperty {get; set;}
public MyClass(){}
}
How do I set the property value to the value of an object without the property changing whenever the object does?
MyClass C1 = new MyClass();
MYClass C2 = new MyClass();
int[] x = new int[3] {1,2,3};
C1.MyProperty = x;
x[2] = 7; //this changes C1.MyProperty to a value of {1,2,7}
C2.MyProperty = x;
I would like the 2 index of the property of C1 to remain a value of 3 even when I change the value of x[2]. Similarly I would like C2 property index 2 value to always be 7. Is there some kind of way i can set the property to something like ValueOf(x)? Do i need some sort of static keyword?