ARTICLE

Using ArrayList in VB.NET

Posted by Sapna Articles | Visual Basic Language May 06, 2011
ArrayList is one of the most flixible data structure from VB.NET Collections.
 
Reader Level:

ArrayList is one of the most flixible data structure from VB.NET Collections. Array is the collection of values of the same data type, As ArrayList contains a simple list of values and very easily we can add , insert , delete , view etc. The ArrayList can be expanded automatically by built-in code, making a dynamic array. It is very flexible becuse we can add without any size information. Here, we describe the ArrayList type in the VB.NET language, which is one of the easiest and more useful data types.

Untitled-1.gif

An ArrayList can support multiple readers concurrently, as long as the collection is not modified. To guarantee the thread safety of the ArrayList, all operations must be done through the wrapper returned by the Synchronized method. The Add method on the VB.NET ArrayList instance type is very commonly used. The Add method appends the object argument to the very end of the internal ArrayList data structure.

Example of ArrayList.Add

Imports
System
Imports System.Collections
 
Public Class MainClass
 
    Shared Sub Main()
        Dim A1 As New ArrayList()
        Dim A2 As New ArrayList()
 
        Dim j As Integer
        For j = 0 To 10
            A1.Add(New worker(j + 50))
            A2.Add((j * 2))
        Next j
 
        For Each j In A2
            Console.Write("{0} ", j.ToString())
        Next  

        Console.WriteLine(ControlChars.Lf)
 
        Dim k As worker
        For Each k In A1
            Console.Write("{0} ", k.ToString())
        Next k
 
        Console.WriteLine(ControlChars.Lf)
        Console.WriteLine("staff{0}", A1.Capacity)
        Console.ReadLine()
    End
Sub

End Class
 
Public Class worker
    Private WID As Integer
 
    Public Sub New(ByVal empID As Integer)
        Me.WID = empID
    End Sub
 
    Public Overrides Function ToString() As String
        Return WID.ToString()
    End Function
 
    Public Property EmpID() As Integer
        Get
            Return WID
        End Get
        Set(ByVal Value As Integer)
            WID = Value
        End Set
    End
Property
End Class

Output

aaa.gif

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor