Pavel

Pavel

  • 1.6k
  • 170
  • 51.1k

List of references to strcutures

Sep 28 2016 12:02 PM

Hello,

I believed that structure is a reference type.

  1. public struct struct_A  
  2. {  
  3.      public int  struct_member1;  
  4.      public int  struct_member2;  
  5.      public int  struct_member3;  
  6. }  
  7.   
  8. struct_A [] arrA_1 = new struct_A [7];  
  9. struct_A [] arrA_2 = new struct_A [7];  
  10.   
  11. List<struct_A> lst_A = new List<struct_A>();  
  12.   
  13. // list initialization  
  14. for (int i = 0; i < arrA_1.Length; i++)  
  15. {  
  16.     lst_A.Add(arrA_1[i];  
  17.     lst_A.Add(arrA_2[i];  
  18. }  
Then I assign arrA_1[0]. struct_member2:
  1. arrA_1[2].struct_member2 = 10;  
and check lst_A[0]. struct_member2:
  1. int check_value = lst_A[0].struct_member2  

The check_value should be 10, but it isn't. Why ?

Thanks in advance.


Answers (5)