Jagged arrays in C++/CLI

PaulW asked on my CP article’s forum whether C++/CLI has support for jagged arrays. In the old syntax, there was no direct syntactical support for jagged arrays and we were left with the rather uneasy option of simulating jagged arrays through contrived code. My first answer to him was that there wasn’t direct support for jagged arrays in the new syntax as far as I knew. But Holger Grund (VC++ MVP) pointed out to me that it was quite easy to do jagged arrays in C++/CLI.

For example, the following C# code :-

int[][] arr = new int[][5]; // C#

corresponds to the following C++ code :-

array<array<int>^>^ arr = gcnew array<array<int>^> (5); // C++

Nice eh?

Advertisements

6 thoughts on “Jagged arrays in C++/CLI

  1. Good question Matt. It’s just that my web host option only gives me MySQL (means I don’t have SQL server). So I can’t use any of the ASP.NET blog apps, and I can’t afford SQL server based hosting options either 😦

    Nish

  2. Gosh… it seems like C++ just can’t escape these ugly, overly complex declarations. Is there any way to make the C++ version easier on the eyes? …a typedef maybe?

    Please keep up with the nice work!
    Roger

  3. Wow, that pingback thing is nice. I was a little surprised when I got a mail notification for a comment and then found it wasn’t a real comment, but a pingback from one of my own blog entries 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s