Vb.Net-Informations.com

  How to VB.Net Dyanamic Array




   Categories

    HOME
    VB.NET
    CSHARP

 
   














How to VB.Net Dyanamic Array

Dynamic Arrays can resize the capability of the Array at runtime .when you are in a situation that you do not know exactly the number of elements to store in array while you making the program. In that situations we are using Dynamic Array .

Initial declaration

Dim scores() As Integer

Resizing

ReDim scores(1)

If you want to keep the existing items in the Array , you can use the keyword Preserve .

ReDim Preserve scores(2)

In this case the Array dynamically allocate one more String value and keep the existing values.


         VB.NET Source Code Download           Print Source Code
         How to VB.Net Dyanamic Array - Download
        
VB.Net Tutorial

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        Dim scores() As Integer

        ReDim scores(1)
        scores(0) = 100
        scores(1) = 200

        For i = 0 To scores.Length - 1
            MsgBox(scores(i))
        Next

        ReDim Preserve scores(2)

        scores(2) = 300

        For i = 0 To scores.Length - 1
            MsgBox(scores(i))
        Next
    End Sub
End Class

When you execute this source code , the first loop shows first two values stored in the Array. Next loop shows the whole value stored in the Array.

VB.NET Collections Related Contents
*     How to use VB.NET ArrayList
*     How to use VB.NET HashTable
*     How to use VB.NET Stack
*     How to use VB.NET Queue
*     How to use VB.NET Arrays
*     How to use VB.NET NameValueCollection

VB.Net Related Topics
*     Microsoft .Net Framework Tutorials
*     VB.NET Language Basics Tutorials
*     VB.NET Program Flow Control Tutorials
*     VB.NET Collections Tutorials
*     VB.NET String Tutorials
*     VB.NET Files Tutorials
*     VB.NET Excel 2007 Tutorials
*     VB.NET Crystal Reports Tutorials
*     VB.NET Communications Tutorial
*     VB.NET ADO.NET Tutorial with source code
*     ADO.NET Data Providers help and Tutorial
*     VB.NET ADO.NET Dataset Tutorial
*     ADO.NET DataAdapter and Dataset
*     VB.NET ADO.NET DataView Tutorial
*     VB.NET Remoting Tutorial
*     VB.NET XML Tutorial
Search here for more CSharp Source Code :

  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2010 All Rights Reserved