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

Capture and play voice with Asterisk ARI -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -