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:

  1. convert array toarray()
  2. modify array desired
  3. 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

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -