How to use VB.NET List
VB.NET List examples
Generic lists were introduced with .Net 2.0 and are the way to go. List is a generic implementation of ArrayList. List can store only one type of objects, that type supplied as its generic parameter. List class is a collection and defined in the System.Collections.Generic namespace and it provides the methods and properties like other Collection classes such as add, insert, remove, search etc.
To use List(Of T), however, you have to understand how to implement the many methods that the .NET Framework provides
The parameter T is the type of elements in the list.
How to add items in List ?
Add integer values in the List
Add string values in the List
How to count number of items exists in a List ?
List.Count property gives you the number of items exists in List
How to retrieve items from List ?
You can retrieve items from List collection by using for loops.
How to insert an item in the List ?
You can use insert(index,item) method to insert an in the specified index.
In the above code the number "zero" is inserted in the index position 1.
How to remove an item from List collection?
List.Remove() can use to remove item from List.
How to check if an item exist in the List ?
You can use List.Contains() method to check an item exists in the List
How to copy an Array to a List ?
Finally clear method remove all the items from List collection.
Difference between list and dictionary in VB.Net
In VB.Net applications both lists and dictionaries are used to store collections of data. List (ICollection ) is simply a set of items and Dictionary(IDictionary) is a set of key-value pairs. The essential difference therefore is in how the containers are indexed data in your VB.Net application. If you want to know more details.....What is the difference between list and dictionary in VB.Net?
The following VB.Net program shows the implementation of the above functionalities in List collection.