As discussed before, arrays are one variable that can hold multiple objects of the same type. However, in .NET, Arrays are also viewed as their own type of object. This means they also come with their own built-in functions. For example, if you want to find the number of objects in an array, you can use:
In the above example, the variable "ElementCount" would end with a value of 3. Although this is helpful for one-dimensional arrays, two-dimensional arrays may be a little more complex when obtaining the full structure. However, we can use the GetUpperBound function for this.
Notice that this array has three rows and two columns. If we didn't know this, we could still figure it out by using this code:
Notice that when I use this, I pass it an integer. This integer represents the index-based dimension I am referencing. For example, I am referencing the first dimension of the array to get the rows. Next, I am referencing the second dimension of the array to get the column. An easy way to remember the rows versus the columns is to simply remember that a one-dimensional array is nothing but a row of objects. Therefore, the second dimension will ALWAYS be adding the columns to the row.
There are some other functions that are included for arrays. This includes:
Now that you have a grasp on arrays, as well as how to use many of the internal functions of Visual Basic, we will start discussing Conditional logic.
Previous Next