如何将Int [] []转换为Double [] []?

时间:2023-01-08 16:01:52

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 [] []锯齿状数组,我想将其转换为Double [] []锯齿状数组。当然我不想更改数组中的值,例如:

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 个解决方案

#1


10  

Try:

尝试:

.Select(x => (double)MyIntegerParse(x))

#2


4  

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

类似这个辅助功能的东西可能会起作用

#1


10  

Try:

尝试:

.Select(x => (double)MyIntegerParse(x))

#2


4  

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

类似这个辅助功能的东西可能会起作用