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 ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.