从int [,]转换为double [] [] []

问题描述 投票:0回答:1
    public static double[][] ConvertToDouble(int[,] arr , int r , int c)
    {
        double[][] matrix = new double[r][c];
        for(int i=0;i<r;i++)
        {
            for(int j=0;j<c;j++)
            {
                matrix[i][j] = Convert.ToDouble(arr[i,j]);  //the error comes in this line
            }
        }

        return matrix;
    }

这里我试图创建一个将int [,]转换为double [] []的函数,但我得到了System.NullReferenceException

c# matrix type-conversion
1个回答
0
投票

在使用矩阵之前,必须将其元素初始化

。您可以像这样初始化元素:
© www.soinside.com 2019 - 2024. All rights reserved.