创建一个列表

列表可以根据需要使用格式填充任何数据类型

Dim aList as New List(Of Type)

例如:

创建一个新的空字符串列表

Dim aList As New List(Of String)

创建一个新的字符串列表,并填充一些数据

VB.NET 2005/2008:

Dim aList as New List(Of String)(New String() {"one", "two", "three"})

VB.NET 2010:

Dim aList as New List(Of String) From {"one", "two", "three"}

-

VB.NET 2015:

Dim aList as New List(Of String)(New String() {"one", "two", "three"})

注意:

如果在运行代码时收到以下内容:

你调用的对象是空的。

确保你声明为 NewDim aList as New List(Of String) 或如果没有 New 声明,请确保将列表设置为新列表 - Dim aList as List(Of String) = New List(Of String)