in c# ,one array of class and two connected instance of it why ?
- by Al0NE
Hi
I wrote the code below :
1. MyClass[] origArr=new MyClass[3];
2. MyClass[] arr1;
3. // filled the array with objects and did some work on it .
4. dgv_1.DataSource=origArr;
5.
6. // Here is the problem :
7. arr1=origArr;
8. // do some work on arr1 ...
9. dgv_2.DataSource=arr1;
For some reason the data in 'origArr' changed when data in 'arr1' change ...
I thought that maybe this happened because 'origArr' and 'arr1' are pointers referring to the same object so I changed line '7' to :
7. origArr.CopyTo(arr1,0);
but it didn't work ... what can i do to make the pointers referring to different objects?