Wednesday, December 21, 2011

VB.NET - Array

Array
     A standard structure for storing data in any programming language is the array. Array can hold set of data of the same type (a set of numbers, a series of data, and so on). An array has a name, as does a variable, and the value store in it can be access by an index.
Declaring array
     Array must be declared with the dim (or public, or private) statement followed by the name of the array and the index of the last element in the array in parentheses.
Example
     Dim arr(15) as Integer
Initializing arrays
     Just as, initializing variables, we can initialize arrays.
     Syntax: =   Dim arr_name As DataType = {entry1, entry2 ….. entry n}

Types of array
In VB.NET the array classified into following types:-
       1. One Dimensional Array: - is used to store data in one flow. At declaring time of this type of array, we use only one subscript.
Example:  Dim marks(5) as integer
In above example, we declare a one dimensional array type integer and name marks. In this, we use one subscript which size is 5.

       2. Two Dimensional Arrays: - we use two subscripts at the declaring time of this array. We separate these subscripts by comma.
Example: dim officeCount (40,5) as Byte
In the above example, we declare a two dimensional array named officeCount. In this first subscripts hold 0 to 40 and second subscript hold 0 to 5 elements. This array has total (40+1) * (5 + 1) = 246 elements.
Two dimensional arrays are also called Rectangle array.
       3. Multi Dimensional Array: - the types of array which use more than two subscripts is called multidimensional array. Visual Basic supports 32 dimensional (subscripts) in array.
Example:  Dim arr(p,q,r,s) as integer

       4. Jagged Array: - Jagged array is the combinations of many arrays. In this each array have different length. A type of array, which each element is a separate array, is called jagged array.
Example:
Dim colors(2)() as Integer
colors(0) = new string{“Red”,”Green”,”Blue”}
colors(1) = new string{“Black”,”white”}
colors(2) = new string{“Yellow”,”Gray”,”Cyan”,”Orange”}



No comments:

Nathuram Godse - The Man Who Killed Gandhi

Nathuram Godse - The Man Who Killed Gandhi (The Other Side of The Story)