O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Create a Jagged Array

Problem

You need to create a nonrectangular array. For example, you might want to create a two-dimensional array in which different rows have different numbers of column elements.

Solution

Don’t attempt this unless required for compatibility reasons—it makes your code less usable and much more obscure. If required, use the Array.CreateInstance method.

Discussion

Jagged arrays (sometimes described as arrays of arrays) introduce complexity, and should be used sparingly. However, they do have legitimate uses and are supported by Visual Basic .NET.

One way to create a multidimensional array is by including multiple sets of closed brackets when you define the array. As an example, the following code creates an array with 12 rows (one ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required