我得到了如何使用 swig 将数组从 C# 传递到 C++ 的答案。请看下面
''' SWIG 接口代码
%module (directors="1") CppTestApp
%{
#include "TestClass.h"
#include "TestDataClass.h"
%}
%include <windows.i>
%include <std_string.i>
%include <arrays_csharp.i>
CSHARP_ARRAYS(char *, string)
%typemap(imtype, inattributes="[In, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0, ArraySubType=UnmanagedType.LPStr)]") char * INPUT[] "string[]"
%apply char * INPUT[] { char * argv [], char * argvqq [] }
%apply int INPUT[] { int sourceArray [] }
%apply double INPUT[] { double sourcedoubleArray [] }
%apply char INPUT[] { char chArray [] }
%apply bool INPUT[] { bool bArray [] }
%apply long INPUT[] { long lArray [] }
%apply float INPUT[] { float fArray [] }
%feature("director") Base;
%include "TestClass.h"
%include "TestDataClass.h"
'''
'''C++代码
class TestClass
{
public:
int times2(int sourceArray[], double sourcedoubleArray[], char* argv[], char chArray[], bool bArray[], float fArray[], long lArray[]);
};
'''
''' 生成的 SWIG C# 代码
[global::System.Runtime.InteropServices.DllImport("CppTestApp", EntryPoint="CSharp_TestClass_times2")]
public static extern int TestClass_times2(global::System.Runtime.InteropServices.HandleRef jarg1, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]int[] jarg2, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]double[] jarg3, [In, global::System.Runtime.InteropServices.MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0, ArraySubType=UnmanagedType.LPStr)]string[] jarg4, string jarg5, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray,ArraySubType=System.Runtime.InteropServices.UnmanagedType.I1)]bool[] jarg6, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]float[] jarg7, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)]int[] jarg8);
'''