无法在VB.NET中声明列表?

red*_*ike 4 vb.net

Dim lstNum As New List(Of Integer)(New Integer() { 3, 6, 7, 9 })
Run Code Online (Sandbox Code Playgroud)

当我键入上面的代码行时,Visual Studio会通知我一个错误

'Microsoft.Office.Interop.Word.List'没有类型参数,因此不能有类型参数.

究竟是什么意思,我该如何解决?我似乎无法创建任何类型的列表.我假设我错过了一些导入但我不熟悉VB.Net足以知道该尝试什么.

Dav*_*now 8

使用Generic.List而不仅仅是List.

Dim lstNum As New Generic.List(Of Integer)(New Integer() { 3, 6, 7, 9 })
Run Code Online (Sandbox Code Playgroud)

由于您已导入Word interop,因此它正在尝试查找Word.List.指定Generic.List将告诉它超出该导入.

  • 更具体地说,确保您正在导入和/或别名System.Collections.Generic命名空间.除非导入System.Collections,否则Generic.List不一定有效. (2认同)

Emm*_*l N 6

尝试添加System.Collections.Generic

 Dim lstNum As New System.Collections.Generic.List(Of Integer)(New Integer() { 3, 6, 7, 9 })
Run Code Online (Sandbox Code Playgroud)