更新时间:2023-02-12 15:44:29
你真的是托管C ++?不是C ++ / CLI?
Do you really mean Managed C++? Not C++/CLI?
您实际上正在使用C ++ / CLI(因为你张贴的错误消息)假设,有两种方法可以做到这一点:
Assuming you're actually using C++/CLI (because of the error message you posted), there are two ways to do this:
array<String^>^ managedArray = gcnew array<String^>(10);
将创建一个管理的阵列,即同一类型在C#中的String []。
will create a managed array, i.e. the same type as string[] in C#.
gcroot<String^>[] unmanagedArray;
将创建一个非托管C ++阵列(我从来没有实际上阵列尝试这一点 - 它与STL容器的效果很好,所以应该在这里工作,太)
will create an unmanaged C++ array (I've never actually tried this with arrays - it works well with stl containers, so it should work here, too).