There is an array

float [,] arr1;

How to convert it to double[,] ?

  • Convert.ToDouble (arr1) ;? - guitarhero

1 answer 1

If by “convert” you mean “create a new array”, then:

 double[,] Convert(float[,] arr) { int d0 = arr.GetLength(0), d1 = arr.GetLength(1); var result = new double[d0, d1]; for (int i0 = 0; i0 < d0; i0++) for (int i1 = 0; i1 < d1; i1++) result[i0, i1] = arr[i0, i1]; return result; } 

If we are talking about type conversion "in place", then, I'm afraid, in any way.

  • And what kind of reinterpret_cast with __makeref magic can it really make the type conversion “in place”? - Anton Komyshan
  • @AntonKomyshan: They can't. If only because the size of the data in memory is different. - VladD