c# - How can I modify individual elements of a vector? -
i want read , write individual elements of vectoroffloat
. problem there's no setter defined, makes brackets + index way of accessing elements read only.
vectoroffloat vector = new vectoroffloat(5); // vector[2] = 2.5f; // not work
there's workaround:
- convert array
toarray()
- modify array desired
- write array
clear()
,push()
float[] array = vector.toarray(); array[2] = 2.5f; vector.clear(); vector.push(array); // work retarded console.writeline(vector[2]);
this seems cumbersome write 1 element is there more direct approach this? also, missing setter worth if can work around it?
the comments correct. way gain access unmanaged array trough startaddress
property returning intptr
.
lock(vector) { var ptr_array=(float*)vector.startaddress.topointer(); ptr_array[4]=1.0f; }
Comments
Post a Comment