VB.NET List
The List class is used to store generic types of collections objects. By using a generic class on the list, we can store one type of object. The List size can be dynamically different depending on the need of the application, such as adding, searching or inserting elements into a list. A VB.NET List class is provided by the System.Collection.Generic namespace.
Properties of the VB.NET List
The following are the commonly used properties of the List.
Property name | Description |
---|---|
Capacity | It is used to obtain or set a number that indicates the number of elements can be placed in a list. |
Count | It is used to count the number of elements available in the List. |
Item | It is used to get or set an item at a specified position of the List. |
VB.NET List Methods
The following are the methods of VB.NET List class for performing various operations like add, search, remove, sort.
Method | Description |
---|---|
Add | As the name represents, the Add() method is used to add an object at the end of the List |
AddRange | It is used to add the elements of the specified collection to the end of the List. |
Clear | It is used to clear all records from the List. |
Contains | It is used to validate whether the specified object exists in the List or not. |
CopyTo | A CopyTo() method is used to copy all records of a list into a one-dimensional array. |
Find | A Find() method is used to search for a specified element from a list that matches the defined state and returns the first occurrence. |
FindAll | A FindAll() method is used to fetch all the elements from a list that matches the condition defined by the specified predicate. |
Insert | It is used to insert an element at the specified position of the List. |
InsertRange | It is used to insert all elements of a specified collection in a list start from a specified location. |
Remove | By using the Remove() method, we can delete a specified element from the list. |
RemoveAt | By using the RemoveAt() method in a list, we can delete an element from the specified location in a list. |
Reverse | The Reverse() method is used to reverse the order list of elements. |
Sort | A Sort() method is used to sort the elements of the list. |
ToArray | It is used to copy all the elements of the list to a new array object. |
Let us create a program to understand how we can add new elements to a dynamic array in the VB.NET programming language.
Ar_List.vb
Output:
Let us create a program to understand the Insert(), Contains(), Copy array to List, and Sort() function in the VB.NET.
A_List2.vb
Output: