ArrayList is a generic collection in VB.NET that can store a dynamically sized list of objects. It is similar to an array, but it does not have a fixed size. This means that you can add or remove items from an ArrayList without having to resize it.
To use ArrayList in VB.NET, you need to import the System.Collections.ArrayList namespace. You can then create a new ArrayList object and add items to it.
Here is an example of how to use ArrayList in VB.NET:
VB.Net
Imports System.Collections.ArrayList
Sub Main()
' Create a new ArrayList object.
Dim arrayList As New ArrayList()
' Add items to the ArrayList.
arrayList.Add("Item1")
arrayList.Add("Item2")
arrayList.Add("Item3")
' Get the number of items in the ArrayList.
Dim count As Integer = arrayList.Count
' Display the contents of the ArrayList.
Dim item As Object
For Each item In arrayList
Console.WriteLine(item)
Next
End Sub
This code will create a new ArrayList object and add three items to it. The code will then get the number of items in the ArrayList and display the contents of the ArrayList on the console.
Here are some of the advantages of using ArrayList in VB.NET:
It is a dynamically sized collection, so you do not have to worry about resizing it.
It is a generic collection, so you can store any type of object in it.
It is a simple and easy-to-use collection.
Here are some of the disadvantages of using ArrayList in VB.NET:
It is not as efficient as some other collections, such as List.
It does not have as many features as some other collections, such as sorting and searching.
Overall, ArrayList is a versatile and easy-to-use collection in VB.NET. It is a good choice for storing a dynamically sized list of objects.
It represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. However, unlike array, you can add and remove items from a list at a specified position using an index and the array resizes itself automatically. It also allows dynamic memory allocation, adding, searching and sorting items in the list.
Module Module1 Sub Main() Dim list As ArrayList = New ArrayList() Dim i As Integer Console.WriteLine("Adding some numbers:") list.Add(45) list.Add(78) list.Add(33) list.Add(56) list.Add(12) list.Add(23) list.Add(9) Console.WriteLine("Capacity: {0} ", list.Capacity) Console.WriteLine("Total Count: {0}", list.Count) Console.Write("Record: ") For Each i In list Console.Write("{0} ", i) Next i Console.WriteLine() Console.Write("Sorted Record: ") list.Sort() For Each i In list Console.Write("{0} ", i) Next i Console.WriteLine() Console.ReadKey() End Sub End Module
Liked By
Write Answer
ArrayList in vb.net
Join MindStick Community
You have need login or register for voting of answers or question.
Aryan Kumar
06-Jul-2023ArrayList is a generic collection in VB.NET that can store a dynamically sized list of objects. It is similar to an array, but it does not have a fixed size. This means that you can add or remove items from an ArrayList without having to resize it.
To use ArrayList in VB.NET, you need to import the
System.Collections.ArrayList
namespace. You can then create a new ArrayList object and add items to it.Here is an example of how to use ArrayList in VB.NET:
VB.Net
This code will create a new ArrayList object and add three items to it. The code will then get the number of items in the ArrayList and display the contents of the ArrayList on the console.
Here are some of the advantages of using ArrayList in VB.NET:
Here are some of the disadvantages of using ArrayList in VB.NET:
Overall, ArrayList is a versatile and easy-to-use collection in VB.NET. It is a good choice for storing a dynamically sized list of objects.
Anonymous User
23-Dec-2015It represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. However, unlike array, you can add and remove items from a list at a specified position using an index and the array resizes itself automatically. It also allows dynamic memory allocation, adding, searching and sorting items in the list.