Converting from a jagged array to double pointer in C#

后端 未结 3 947
无人及你
无人及你 2020-12-09 18:31

Simple question here: is there any way to convert from a jagged array to a double pointer?

e.g. Convert a double[][] to double**

T

3条回答
  •  遥遥无期
    2020-12-09 19:18

    A double[][] is an array of double[], not of double* , so to get a double** , we first need a double*[]

    double[][] array = //whatever
    //initialize as necessary
    
    fixed (double* junk = &array[0][0]){
    
        double*[] arrayofptr = new double*[array.Length];
        for (int i = 0; i < array.Length; i++)
            fixed (double* ptr = &array[i][0])
            {
                arrayofptr[i] = ptr;
            }
    
        fixed (double** ptrptr = &arrayofptr[0])
        {
            //whatever
        }
    }
    

    I can't help but wonder what this is for and if there is a better solution than requiring a double-pointer.

提交回复
热议问题