ArrayList in VB.NET

ArrayList is one of the most flexible data structure from VB.NET Collections.
  • 6126

ArrayList is one of the most flexible 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 because 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

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.