How to convert Int [] [] to Double [] []?

Guys, sorry for asking the main question,

I have a problem when I have an Int[][] jagged array, and I want to convert it to a Double[][] jagged array. Of course, I do not want to change the value inside the array, for example:

 int[2][1] = 25 

and when it converts to double,

 int[2][1] = 25 

still the same.

here is my code

 value = File.ReadLines(filename) .Select(line => line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(MyIntegerParse) .ToArray() ) .ToArray(); 

So, I have a value [] [], which is an integer type. and I want to convert it to double.

Thanks for any help.

+7
source share
2 answers

Try:

 .Select(x => (double)MyIntegerParse(x)) 
+10
source
 private double[][] intarraytodoublearray(int[][] val) { var ret = new double[val.Length][]; for (int i = 0; i < val.Length; i++ ) { ret[i] = new double[val[i].Length]; for (int j = 0; j < val[i].Length; j++) { ret[i][j] = (double)val[i][j]; } } return ret; } 

something like this helper function might work

+4
source

All Articles