in c# ,one array of class and two connected instance of it why ?

Posted by Al0NE on Stack Overflow See other posts from Stack Overflow or by Al0NE
Published on 2010-03-15T16:40:26Z Indexed on 2010/03/15 16:49 UTC
Read the original article Hit count: 202

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about classes