
Although both the List and array types in the VB.NET programming language are useful, in some program contexts you require the opposite type. In other words, you need to convert from an array to a List, and from a List to an array. In the newer .NET Framework versions, you can do this with extension methods ToArray and ToList.
These VB programs convert Lists and arrays. They use ToArray and ToList.

Intially, this example creates a new List of Integer types and then adds three elements to it. Then, it invokes the ToArray extension method on that collection and assigns the result to a new reference local variable of array type. Next, it invokes the ToList extension method on the array collection and assigns the result to another List variable. The program shows, essentially, how any List and array of equivalent element type can be converted back and forth.
Program that uses ToArray and ToList [VB.NET]
Module Module1
Sub Main()
' Create a list and add three elements to it.
Dim list As List(Of Integer) = New List(Of Integer)
list.Add(1)
list.Add(2)
list.Add(3)
' Convert the list to an array.
Dim array As Integer() = list.ToArray
Console.WriteLine(array.Length)
' Convert the array to a list.
Dim list2 As List(Of Integer) = array.ToList
Console.WriteLine(list2.Count)
End Sub
End Module
Output
3
3
Newer frameworks required. The ToArray and ToList extension methods are part of the System.Linq namespace in the .NET Framework. This namespace was introduced in .NET 3.5; if you are targeting an older framework, this example will not work correctly. In this case, you can use the List constructor or imperative copying of elements in loops.
In this tutorial, we saw how you can invoke the ToArray and ToList extension methods to declaratively and clearly convert between list and array types in the VB.NET programming language. Further, we described the limitations of these methods: they must receive compatible element types and the newer frameworks must be targeted in your solution.
VB.NET Tutorials