CLocation是一个C ++ CLI value class
(在C#中是struct
,公共成员x
,y
,z
。
List<CLocation>^ listloc = gcnew List<CLocation>;
listloc->Add (CLocation (1,2,3));
listloc[0].x = 5; // FAILS, '5' is not stored.
array<CLocation>^ aloc = gcnew array<CLocation>(1);
aloc[0] = CLocation (1,2,3);
aloc[0].x = 5; // WORKS
为什么5
没有保存在列表中对象的成员中,而它完全保存在数组对象的成员中?
列表访问是否返回了对象的副本,正如Marc Gravell在In C#, are the values in a List<struct> boxed?中所写的那样?