2

I am working on converting a C# project to a C++/CLI project. I came across this code and wanted to verify that I am using the proper C++/CLI syntax. I am pretty sure I am doing it wrong, just setting parameters when I want to set the size of the dimensions.

Original C#:

public double[][] _ARRAY = new double[num][];

C++/CLI:

array<double, 2>^ _ARRAY = gcnew array<double, 2>{ {num}, {} };

1 Answer 1

4

That IS how you create a multidimensional array in C++/CLI. But the C# isn't actually a multidimensional array at all.

These two are the same:

/* C# */ public double[][] arrayOfArray;
/* C++/CLI */ array<array<double>^>^ arrayOfArray;

and so are these:

/* C# */ public double [,] array2D;
/* C++/CLI */ array<double,2>^ array2D;

A real two-dimensional array can't be half-dimensioned as you show, that's only possible with a jagged array (array of arrays). For the jagged array, C++/CLI should certainly allow

arrayOfArray = gcnew array<array<double>^>(num);

which is (just like the C# code in your question) an array of (initially null) managed handles to arrays.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.