下面的 C# 代码是否与尝试实现与 C++ 代码相同的等效方式?有没有办法避免复制(而不是将整个数组发送到函数)?
C++
static void somefunction(double* v, int nb)
{
//something that will update v[0],v[1], ... v[nb-1]
}
double * myarray=new double[100];
somefunction(&myarray[10],5);
//...
delete [] myarray;
C#
static void somefunction(double[] v, int nb)
{
//something that will update v[0],v[1], ... v[nb-1]
}
double[] myarray=new double[100];
double[] temp_array=new double[5];
somefunction(temp_array,5);
temp_array.CopyTo(myarray,10);