Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Nov 28, 2001



Application Security Testing: An Integral Part of DevOps

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 dimensions
Dim sArray(,) As String = CType(myArray, _

Dim i As Int32
For i = 0 To sArray.Rank - 1
	Console.WriteLine _
	("dimension {0} , LowerBound = {1}, _
		UpperBound = {2}", _
	i, sArray.GetLowerBound(i), _


Note: You cannot cast to single dimension arrays because VB.NET creates them as vectors.
Bill McCarthy
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date