Declaring, allocating and initializing arrays : Array « Data Structure « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Data Structure » ArrayScreenshots 
Declaring, allocating and initializing arrays
Declaring, allocating and initializing arrays

Imports System

Public Class MainClass

    Shared Sub Main(ByVal args As String())
      Dim As Integer

      Dim array As Integer()          ' declare array variable
      Dim array1, array2 As Integer() ' declare two arrays

      array = New Integer(9) {} ' allocate memory for array

      ' initializer list specifies number of elements
      ' and value of each element
      array1 = New Integer() {3227641895, _
         1490706037}

      ' allocate array2 based on length of array1
      array2 = New Integer(array1.GetUpperBound(0)) {}

      ' set values in array2 by a calculation
      For i = To array2.GetUpperBound(0)
         array2(i* i
      Next

      Console.WriteLine"Subscript " & vbTab & "Array" & vbTab & _
         "Array1" & vbTab & "Array2" & vbCrLf )

      ' display values in array
      For i = To array.GetUpperBound(0)
         Console.WriteLinei & vbTab & array(i& vbTab & _
            array1(i& vbTab & array2(i& vbCrLf )
      Next

      Console.WriteLine(  vbCrLf & "The array contains " & _
         array.Length & " elements." )

    End Sub
End Class

           
       
Related examples in the same category
1.Bounded array ExampleBounded array Example
2.For Each loops through ArrayFor Each loops through Array
3.Two ways to loop through ArrayTwo ways to loop through Array
4.A simple class to store in the array
5.Array UBoundArray UBound
6.Set Array Element Value by Index
7.Array IndexOf and LastIndexOfArray IndexOf and LastIndexOf
8.Use Array CreateInstance to Create ArrayUse Array CreateInstance to Create Array
9.Array Performance Test: One-dimensional arrayArray Performance Test: One-dimensional array
10.Free array's memory
11.Array Performance Test: SetValue(i, i)Array Performance Test: SetValue(i, i)
12.Use For Each/Next to find a minimum gradeUse For Each/Next to find a minimum grade
13.Reference an Element in an Array by IndexReference an Element in an Array by Index
14.Array Upper Bound and Lower BoundArray Upper Bound and Lower Bound
15.Init an Array in DeclarationInit an Array in Declaration
16.Array Length PropertyArray Length Property
17.Declare an Array and reference its memberDeclare an Array and reference its member
18.Store your won Class in an ArrayStore your won Class in an Array
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.