devxlogo

Arrays With Non-Zero Lower Bounds

In VB.NET, you can use the System.Array class to create an array with non-zero lower bounds. To do this, use the System.Array.CreateInstance method: Array.CreateInstance(Type, Lengths(), LowerBounds( ) ).If the array you create has two or more dimensions, you can cast it to a normal array. This example creates an array of strings equivalent to Dim sArray(5 To 14, 8 To 27):

 Dim Lengths() As Int32 = {10, 20}Dim LowerBounds() As Int32 = {5, 8}Dim myArray As Array = _	Array.CreateInstance(GetType(String), _	Lengths, LowerBounds)' have to declare the array with the correct' number of dimensionsDim sArray(,) As String = CType(myArray, _	String(,))Dim i As Int32For i = 0 To sArray.Rank - 1	Console.WriteLine _	("dimension {0} , LowerBound = {1}, _		UpperBound = {2}", _	i, sArray.GetLowerBound(i), _	sArray.GetUpperBound(i))Next

Note: You cannot cast to single dimension arrays because VB.NET creates them as vectors.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Seven Service Boundary Mistakes That Create Technical Debt

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.