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 an Array That Is Not Bounded at Zero

Problem

You need to create an array that follows idiosyncratic dimension numbering (for example, has a lower bound of –2 or 5 instead of 0).

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

The Array.CreateInstance method allows you to create a nonstandard array. As parameters, you specify the type of object that will be contained in the array, the length of the array, and the lower bounds. The latter two parameters must be submitted as arrays, with one entry for each dimension. (This means you can use the CreateInstance method to create a jagged array that has different ...

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