从交错数组转换为加倍在C#中的指针 [英] Converting from a jagged array to double pointer in C#
问题描述
在这里简单的问题:有没有办法从一个交错数组转换为双指针?
Simple question here: is there any way to convert from a jagged array to a double pointer?
例如。转换双击[] []
到双**
这不能做只是遗憾的是铸造(因为它可以在普通的旧C),很遗憾。使用固定
语句似乎并不要么解决问题。是否有任何(preferably尽可能高效)的方式在C#中做到这一点?我怀疑解决方案可能不是很明显的是,虽然我希望仍然直白。
This can't be done just by casting unfortunately (as it can in plain old C), unfortunately. Using a fixed
statement doesn't seem to resolve the problem either. Is there any (preferably as efficient as possible) way to accomplish this in C#? I suspect the solution may not be very obvious at all, though I'm hoping for a straightforward one nonetheless.
推荐答案
一个双重[] []是一个数组双[],而不是双*的,因此要获得一个双**,我们首先需要一个双* []
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.
这篇关于从交错数组转换为加倍在C#中的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!