8
votes

Guys, sorry for asking basic question,

i have a problem here where I have a Int[][] jagged array, and I want to convert it to Double[][] jagged array. Of course I don't want to change the value inside the array for example:

int[2][1] = 25

and when it converted to double,

int[2][1] = 25

still the same.

here's my code,

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

So i have value[][] which is type is integer. and i want to convert it to double.

Thanks for any help.

2
try to cast (double)MyIntegerParse - Stecya
sorry, but put in where? in .Select(MyIntegerParse)? - Reza
.Select((double)MyIntegerParse) - Stecya
@Stecya: Actually, he should use .Select(x => (double)MyIntegerParse(x)) - digEmAll
@digEmAll : you are right. Should post it like answer - Stecya

2 Answers

11
votes

Try:

.Select(x => (double)MyIntegerParse(x))
4
votes
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 helperfunction might work