VB.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      About


  How to VB.NET ArrayList

ArrayList is one of the most flixible data structure from VB.NET Collections. ArrayList contains a simple list of values and very easily we can add , insert , delete , view etc.. to do with ArrayList. It is very flexible becuse we can add without any size information , that is it grow dynamically and also shrink .

Important functions in ArrayList

Add : Add an Item in an ArrayList

Insert : Insert an Item in a specified position in an ArrayList

Remove : Remove an Item from ArrayList

RemoveAt: remeove an item from a specified position

Sort : Sort Items in an ArrayList

How to add an Item in an ArrayList ?

Syntax : ArrayList.add(Item)

Item : The Item to be add the ArrayList

Dim ItemList As New ArrayList()

ItemList.Add("Item4")

How to Insert an Item in an ArrayList ?

Syntax : ArrayList.insert(index,item)

index : The position of the item in an ArrayList

Item : The Item to be add the ArrayList

ItemList.Insert(3, "item6")

How to remove an item from arrayList ?

Syntax : ArrayList.Remove(item)

Item : The Item to be add the ArrayList

ItemList.Remove("item2")

How to remove an item in a specified position from an ArrayList ?

Syntax : ArrayList.RemoveAt(index)

index : the position of an item to remove from an ArrayList

ItemList.RemoveAt(2)

How to sort ArrayList ?

Syntax : ArrayListSort()

The following VB.NET source code shows some function in ArrayList

         VB.NET Source Code Download           Print Source Code
         How to VB.NET ArrayList - Download
        
C# 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 ItemList As New ArrayList()
        ItemList.Add("Item4")
        ItemList.Add("Item5")
        ItemList.Add("Item2")
        ItemList.Add("Item1")
        ItemList.Add("Item3")
        MsgBox("Shows Added Items")
        For i = 0 To ItemList.Count - 1
            MsgBox(ItemList.Item(i))
        Next
        'insert an item
        ItemList.Insert(3, "Item6")
        'sort itemms in an arraylist
        ItemList.Sort()
        'remove an item
        ItemList.Remove("Item1")
        'remove item from a specified index
        ItemList.RemoveAt(3)
        MsgBox("Shows final Items the ArrayList")
        For i = 0 To ItemList.Count - 1
            MsgBox(ItemList.Item(i))
        Next
    End Sub
End Class

When you execute this program , at first add five items in the arraylist and displays. Then again one more item inserted in the third position , and then sort all items. Next it remove the item1 and also remove the item in the third position . Finally it shows the existing items.


VB.NET Collections Related Contents
*     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 Dyanamic Arrays
*     How to use VB.NET NameValueCollection


   Home      VB.NET      C#
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
*     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
*     VB.NET DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.