Programming Tutorials

ArrayList data structure in VB.net

By: Issac in VB.net Tutorials on 2009-01-30  

In VB.net, the ArrayList class is used to create an array-like collection that can hold a variable number of objects. It is a part of the System.Collections namespace and provides methods to add, remove, and search for elements in the list.

Here is an example of creating and using an ArrayList in VB.net:

Imports System.Collections

Module Module1
    Sub Main()
        ' Create an ArrayList object
        Dim list As New ArrayList()

        ' Add elements to the list
        list.Add("apple")
        list.Add("orange")
        list.Add("banana")

        ' Remove an element from the list
        list.Remove("orange")

        ' Access elements in the list
        Console.WriteLine("First element: " & list(0))
        Console.WriteLine("Second element: " & list(1))

        ' Search for an element in the list
        Dim index As Integer = list.IndexOf("banana")
        Console.WriteLine("Index of 'banana': " & index)

        Console.ReadLine()
    End Sub
End Module

In this example, we create an ArrayList object called list and add three string elements to it. We then remove the second element ("orange"), access the first and second elements using the indexing syntax, and search for the index of the element "banana". Finally, we output the results to the console.






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in VB.net )

Latest Articles (in VB.net)