从本机代码将cli::array转换为本机数组,可以使用以下方法:
cli::array<int>^ cliArray = gcnew cli::array<int>(5);
cliArray[0] = 1;
cliArray[1] = 2;
cliArray[2] = 3;
cliArray[3] = 4;
cliArray[4] = 5;
int nativeArray[5];
for (int i = 0; i < 5; i++) {
nativeArray[i] = cliArray[i];
}
cli::array<int>^ cliArray = gcnew cli::array<int>(5);
cliArray[0] = 1;
cliArray[1] = 2;
cliArray[2] = 3;
cliArray[3] = 4;
cliArray[4] = 5;
int nativeArray[5];
pin_ptr<int> pinnedArray = &nativeArray[0];
Marshal::Copy(cliArray, 0, IntPtr(pinnedArray), 5);
这样,就可以将cli::array转换为本机数组。
领取专属 10元无门槛券
手把手带您无忧上云