C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Next: It invokes the ToList Extension on the array and assigns the result to another List variable.
Program: This shows how any List and array of equivalent element type can be converted back and forth.
ToListVB.NET program that uses ToArray and ToList
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
Tip: In this case, you can use the List constructor or imperative copying of elements in loops.
List